diff options
author | Werner Koch <wk@gnupg.org> | 2006-10-20 13:38:48 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2006-10-20 13:38:48 +0200 |
commit | 58785c880d4540e0f75738b3b10a8a03c35d5ee1 (patch) | |
tree | 3b1a8732c3d3f8132bfaab9447a9252d4235b852 /common/convert.c | |
parent | * gpgkeys_hkp.c (curl_mrindex_writer): Print a warning if we see HTML (diff) | |
download | gnupg2-58785c880d4540e0f75738b3b10a8a03c35d5ee1.tar.xz gnupg2-58785c880d4540e0f75738b3b10a8a03c35d5ee1.zip |
Allow to select X.509 certificates using the keygrip.
Diffstat (limited to 'common/convert.c')
-rw-r--r-- | common/convert.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/common/convert.c b/common/convert.c index 66f612063..d5301b8e7 100644 --- a/common/convert.c +++ b/common/convert.c @@ -30,6 +30,35 @@ #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) +/* Convert STRING consisting of hex characters into its binary + representation and store that at BUFFER. BUFFER needs to be of + LENGTH bytes. The function check that the STRING will convert + exactly to LENGTH bytes. The string is delimited by either end of + string or a white space character. The function returns -1 on + error or the length of the parsed string. */ +int +hex2bin (const char *string, void *buffer, size_t length) +{ + int i; + const char *s = string; + + for (i=0; i < length; ) + { + if (!hexdigitp (s) || !hexdigitp (s+1)) + return -1; /* Invalid hex digits. */ + ((unsigned char*)buffer)[i++] = xtoi_2 (s); + s += 2; + } + if (*s && (!isascii (*s) || !isspace (*s)) ) + return -1; /* Not followed by Nul or white space. */ + if (i != length) + return -1; /* Not of expected length. */ + if (*s) + s++; /* Skip the delimiter. */ + return s - string; +} + + /* Convert STRING consisting of hex characters into its binary representation and store that at BUFFER. BUFFER needs to be of LENGTH bytes. The function check that the STRING will convert exactly to LENGTH @@ -73,7 +102,6 @@ hexcolon2bin (const char *string, void *buffer, size_t length) } - static char * do_bin2hex (const void *buffer, size_t length, char *stringbuf, int with_colon) { |