1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

card: New command 'authenticate'.

* tools/card-tool-misc.c (hex_to_buffer): New.
* tools/gpg-card-tool.c (get_data_from_file): Change to allow returning
a string.
(cmd_authenticate): New.
(cmds): Add command "authenticate".

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-01-31 16:06:47 +01:00
parent 1d57450f3e
commit da38325740
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
3 changed files with 118 additions and 6 deletions

View file

@ -42,3 +42,38 @@ find_kinfo (card_info_t info, const char *keyref)
return kinfo;
return NULL;
}
/* Convert STRING into a newly allocated buffer while translating the
* hex numbers. Blanks and colons are allowed to separate pairs of
* hex digits. Returns NULL on error or a newly malloced buffer and
* its length in LENGTH. */
void *
hex_to_buffer (const char *string, size_t *r_length)
{
unsigned char *buffer;
const char *s;
size_t n;
buffer = xtrymalloc (strlen (string)+1);
if (!buffer)
return NULL;
for (s=string, n=0; *s; s++)
{
if (ascii_isspace (*s) || *s == ':')
continue;
if (hexdigitp (s) && hexdigitp (s+1))
{
buffer[n++] = xtoi_2 (s);
s++;
}
else
{
xfree (buffer);
gpg_err_set_errno (EINVAL);
return NULL;
}
}
*r_length = n;
return buffer;
}