Use C99 uint32_t rather than u_int32_t
[onak.git] / keyid.c
diff --git a/keyid.c b/keyid.c
index 0516f477e028eac7d7fb584be15a90259c106dfb..a7051f2d23552dc1bc8b5f9c464ced26c11f3f05 100644 (file)
--- a/keyid.c
+++ b/keyid.c
@@ -1,11 +1,23 @@
 /*
  * keyid.c - Routines to calculate key IDs.
  *
- * Jonathan McDowell <noodles@earth.li>
+ * Copyright 2002,2011 Jonathan McDowell <noodles@earth.li>
  *
- * 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 <string.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 
@@ -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;
+}