mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Allow to select X.509 certificates using the keygrip.
This commit is contained in:
parent
11935a4c18
commit
58785c880d
13 changed files with 251 additions and 3 deletions
|
@ -1,3 +1,7 @@
|
|||
2006-10-20 Werner Koch <wk@g10code.com>
|
||||
|
||||
* convert.c (hex2bin): New.
|
||||
|
||||
2006-10-17 Werner Koch <wk@g10code.com>
|
||||
|
||||
* estream.c (struct estream_internal, es_initialize)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,93 @@
|
|||
} while(0)
|
||||
|
||||
|
||||
static void
|
||||
test_hex2bin (void)
|
||||
{
|
||||
static const char *valid[] = {
|
||||
"00112233445566778899aabbccddeeff11223344",
|
||||
"00112233445566778899AABBCCDDEEFF11223344",
|
||||
"00112233445566778899AABBCCDDEEFF11223344 blah",
|
||||
"00112233445566778899AABBCCDDEEFF11223344\tblah",
|
||||
"00112233445566778899AABBCCDDEEFF11223344\nblah",
|
||||
NULL
|
||||
};
|
||||
static const char *invalid[] = {
|
||||
"00112233445566778899aabbccddeeff1122334",
|
||||
"00112233445566778899AABBCCDDEEFF1122334",
|
||||
"00112233445566778899AABBCCDDEEFG11223344",
|
||||
"00 112233445566778899aabbccddeeff11223344",
|
||||
"00:112233445566778899aabbccddeeff11223344",
|
||||
":00112233445566778899aabbccddeeff11223344",
|
||||
"0:0112233445566778899aabbccddeeff11223344",
|
||||
"00112233445566778899aabbccddeeff11223344:",
|
||||
"00112233445566778899aabbccddeeff112233445",
|
||||
"00112233445566778899aabbccddeeff1122334455",
|
||||
"00112233445566778899aabbccddeeff11223344blah",
|
||||
NULL
|
||||
};
|
||||
static const char *valid2[] = {
|
||||
"00",
|
||||
"00 x",
|
||||
NULL
|
||||
};
|
||||
static const char *invalid2[] = {
|
||||
"",
|
||||
"0",
|
||||
"00:",
|
||||
"00x",
|
||||
" 00",
|
||||
NULL
|
||||
};
|
||||
unsigned char buffer[20];
|
||||
int len;
|
||||
int i;
|
||||
|
||||
|
||||
for (i=0; valid[i]; i++)
|
||||
{
|
||||
len = hex2bin (valid[i], buffer, sizeof buffer);
|
||||
if (len < 0)
|
||||
fail (i);
|
||||
if (memcmp (buffer, ("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa"
|
||||
"\xbb\xcc\xdd\xee\xff\x11\x22\x33\x44"), 20))
|
||||
fail (i);
|
||||
}
|
||||
if (hex2bin (valid[0], buffer, sizeof buffer) != 40)
|
||||
fail (0);
|
||||
if (hex2bin (valid[2], buffer, sizeof buffer) != 41)
|
||||
fail (0);
|
||||
|
||||
for (i=0; invalid[i]; i++)
|
||||
{
|
||||
len = hex2bin (invalid[i], buffer, sizeof buffer);
|
||||
if (!(len < 0))
|
||||
fail (i);
|
||||
}
|
||||
|
||||
for (i=0; valid2[i]; i++)
|
||||
{
|
||||
len = hex2bin (valid2[i], buffer, 1);
|
||||
if (len < 0)
|
||||
fail (i);
|
||||
if (memcmp (buffer, "\x00", 1))
|
||||
fail (i);
|
||||
}
|
||||
if (hex2bin (valid2[0], buffer, 1) != 2)
|
||||
fail (0);
|
||||
if (hex2bin (valid2[1], buffer, 1) != 3)
|
||||
fail (0);
|
||||
|
||||
for (i=0; invalid2[i]; i++)
|
||||
{
|
||||
len = hex2bin (invalid2[i], buffer, 1);
|
||||
if (!(len < 0))
|
||||
fail (i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
test_hexcolon2bin (void)
|
||||
{
|
||||
|
@ -195,6 +282,7 @@ int
|
|||
main (int argc, char **argv)
|
||||
{
|
||||
|
||||
test_hex2bin ();
|
||||
test_hexcolon2bin ();
|
||||
test_bin2hex ();
|
||||
test_bin2hexcolon ();
|
||||
|
|
|
@ -157,6 +157,7 @@ unsigned char *make_simple_sexp_from_hexstr (const char *line,
|
|||
size_t *nscanned);
|
||||
|
||||
/*-- convert.c --*/
|
||||
int hex2bin (const char *string, void *buffer, size_t length);
|
||||
int hexcolon2bin (const char *string, void *buffer, size_t length);
|
||||
char *bin2hex (const void *buffer, size_t length, char *stringbuf);
|
||||
char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue