From 58785c880d4540e0f75738b3b10a8a03c35d5ee1 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 20 Oct 2006 11:38:48 +0000 Subject: Allow to select X.509 certificates using the keygrip. --- common/convert.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'common/convert.c') 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) { -- cgit v1.2.3