From fcc02ac22a1175b63436e2b6b1cc002c847b12f5 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sat, 21 Feb 2004 22:12:29 +0000 Subject: * miscutil.c (hextobyte): Moved here from g10/misc.c so I can use it in the keyserver helpers. --- util/miscutil.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'util/miscutil.c') diff --git a/util/miscutil.c b/util/miscutil.c index 16c382d86..82fe6a935 100644 --- a/util/miscutil.c +++ b/util/miscutil.c @@ -430,3 +430,28 @@ match_multistr(const char *multistr,const char *match) return 0; } + +int +hextobyte( const char *s ) +{ + int c; + + if( *s >= '0' && *s <= '9' ) + c = 16 * (*s - '0'); + else if( *s >= 'A' && *s <= 'F' ) + c = 16 * (10 + *s - 'A'); + else if( *s >= 'a' && *s <= 'f' ) + c = 16 * (10 + *s - 'a'); + else + return -1; + s++; + if( *s >= '0' && *s <= '9' ) + c += *s - '0'; + else if( *s >= 'A' && *s <= 'F' ) + c += 10 + *s - 'A'; + else if( *s >= 'a' && *s <= 'f' ) + c += 10 + *s - 'a'; + else + return -1; + return c; +} -- cgit