X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/3cdd1ba5400b97412d8e69fdcf59284b7cde6e28..a241edc87bed49d6bc5dc3c4c99786a921ae7c8a:/keyid.c diff --git a/keyid.c b/keyid.c index 0516f47..a7051f2 100644 --- a/keyid.c +++ b/keyid.c @@ -1,11 +1,23 @@ /* * keyid.c - Routines to calculate key IDs. * - * Jonathan McDowell + * Copyright 2002,2011 Jonathan McDowell * - * Copyright 2002 Project Purple + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include @@ -216,3 +228,32 @@ void get_skshash(struct openpgp_publickey *key, struct skshash *hash) md5_finish_ctx(&md5_context, &hash->hash); free_packet_list(packets); } + +uint8_t hexdigit(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + else + return 0; +} + +int parse_skshash(char *search, struct skshash *hash) +{ + int i, len; + + len = strlen(search); + if (len > 32) { + return 0; + } + + for (i = 0; i < len; i += 2) { + hash->hash[i >> 1] = (hexdigit(search[i]) << 4) + + hexdigit(search[i + 1]); + } + + return 1; +}