diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2008-06-16 10:24:39 -0400 |
---|---|---|
committer | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2008-06-16 10:24:39 -0400 |
commit | 9715df03ccc1620db97d3fea50e5031f6ed36fde (patch) | |
tree | f268e210161ea693bd46f341a0c073392f038411 /src | |
parent | 785736d891f6c61eb5d7f4f10687ef9a0d920c3b (diff) |
genericized the hex printing capabilities.
Diffstat (limited to 'src')
-rw-r--r-- | src/keytrans/gnutls-helpers.c | 19 | ||||
-rw-r--r-- | src/keytrans/gnutls-helpers.h | 2 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/keytrans/gnutls-helpers.c b/src/keytrans/gnutls-helpers.c index d5f3719..5b4c46a 100644 --- a/src/keytrans/gnutls-helpers.c +++ b/src/keytrans/gnutls-helpers.c @@ -15,6 +15,8 @@ /* for exit() */ #include <unistd.h> +#include <assert.h> + /* higher levels allow more frivolous error messages through. this is set with the MONKEYSPHERE_DEBUG variable */ static int loglevel = 0; @@ -41,13 +43,20 @@ void init_keyid(gnutls_openpgp_keyid_t keyid) { void make_keyid_printable(printable_keyid out, gnutls_openpgp_keyid_t keyid) { + assert(sizeof(out) >= 2*sizeof(keyid)); + hex_print_data((char*)out, (const char*)keyid, sizeof(keyid)); +} + +/* you must have twice as many bytes in the out buffer as in the in buffer */ +void hex_print_data(char* out, const char* in, size_t incount) +{ static const char hex[16] = "0123456789ABCDEF"; - unsigned int kix = 0, outix = 0; + unsigned int inix = 0, outix = 0; - while (kix < sizeof(gnutls_openpgp_keyid_t)) { - out[outix] = hex[(keyid[kix] >> 4) & 0x0f]; - out[outix + 1] = hex[keyid[kix] & 0x0f]; - kix++; + while (inix < incount) { + out[outix] = hex[(in[inix] >> 4) & 0x0f]; + out[outix + 1] = hex[in[inix] & 0x0f]; + inix++; outix += 2; } } diff --git a/src/keytrans/gnutls-helpers.h b/src/keytrans/gnutls-helpers.h index 670d5ff..f196456 100644 --- a/src/keytrans/gnutls-helpers.h +++ b/src/keytrans/gnutls-helpers.h @@ -48,6 +48,8 @@ void collapse_printable_keyid(gnutls_openpgp_keyid_t out, printable_keyid in); int convert_string_to_keyid(gnutls_openpgp_keyid_t out, const char* str); int convert_string_to_printable_keyid(printable_keyid out, const char* str); +/* you must have twice as many bytes in the out buffer as in the in buffer */ +void hex_print_data(char* out, const char* in, size_t incount); /* functions to get data into datum objects: */ |