Commit 14047d99 authored by Niels Möller's avatar Niels Möller
Browse files

* src/digits.c (simple_decode_hex): New function.

Rev: src/digits.c:1.3
Rev: src/digits.h:1.3
parent 761727e8
......@@ -25,6 +25,7 @@
#include "digit_table.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
......@@ -74,3 +75,28 @@ base64_decode(struct base64_state *state, UINT8 c)
return res;
}
struct lsh_string *
simple_decode_hex(const unsigned char *in)
{
unsigned length = strlen(in);
unsigned i, j;
struct lsh_string *out;
assert(!(length % 2));
out = lsh_string_alloc(length/2);
for (i = j = 0; i<length; )
{
int d1 = hex_digits[in[i++]];
int d2 = hex_digits[in[i++]];
assert(d1 >= 0);
assert(d2 >= 0);
out->data[j++] = (d1 << 4) | d2;
}
return out;
}
......@@ -56,4 +56,7 @@ base64_init(struct base64_state *state, UINT8 terminator);
int
base64_decode(struct base64_state *state, UINT8 c);
/* Only used by the testsuite */
struct lsh_string *simple_decode_hex(const unsigned char *in);
#endif /* LSH_DIGITS_H_INCLUDED */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment