summaryrefslogtreecommitdiffstats
path: root/dirmngr/misc.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2016-01-22 12:54:02 +0100
committerWerner Koch <wk@gnupg.org>2016-01-22 12:54:02 +0100
commit12c665b36cdc4b7189549698fc4cc1b3523b18f5 (patch)
treef13fb432aa615e00f3c104bfc9bd899bc1d06a13 /dirmngr/misc.c
parentdirmngr: Provide the keyserver pool name even if there is no CNAME. (diff)
downloadgnupg2-12c665b36cdc4b7189549698fc4cc1b3523b18f5.tar.xz
gnupg2-12c665b36cdc4b7189549698fc4cc1b3523b18f5.zip
dirmngr: Indicate that serial numbers are hexadecimal.
* dirmngr/misc.c (hexify_data): Add arg with_prefix. Adjust all callers. * dirmngr/crlcache.c (cache_isvalid): Print "0x" in front of the S/N. -- GnuPG-bug-id: 1147 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'dirmngr/misc.c')
-rw-r--r--dirmngr/misc.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/dirmngr/misc.c b/dirmngr/misc.c
index c2c5af16a..ac3856e09 100644
--- a/dirmngr/misc.c
+++ b/dirmngr/misc.c
@@ -59,17 +59,23 @@ hashify_data( const char* data, size_t len )
{
unsigned char buf[20];
gcry_md_hash_buffer (GCRY_MD_SHA1, buf, data, len);
- return hexify_data( buf, 20 );
+ return hexify_data (buf, 20, 0);
}
char*
-hexify_data( const unsigned char* data, size_t len )
+hexify_data (const unsigned char* data, size_t len, int with_prefix)
{
int i;
- char* result = xmalloc( sizeof( char ) * (2*len+1));
+ char *result = xmalloc (2*len + (with_prefix?2:0) + 1);
+ char *p;
+
+ if (with_prefix)
+ p = stpcpy (result, "0x");
+ else
+ p = result;
- for( i = 0; i < 2*len; i+=2 )
- sprintf( result+i, "%02X", *data++);
+ for (i = 0; i < 2*len; i+=2 )
+ snprintf (p+i, 3, "%02X", *data++);
return result;
}