From: Arran Cudbard-Bell Date: Wed, 25 Jun 2014 16:39:42 +0000 (+0100) Subject: Add fr_abin2hex X-Git-Tag: release_3_0_4_rc2~182 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=freeradius.git;a=commitdiff_plain;h=0fcc5a0087e3d9638d0766b583e459a971b6c2e5 Add fr_abin2hex --- diff --git a/src/include/libradius.h b/src/include/libradius.h index bc2bb87..747e846 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -652,6 +652,7 @@ uint8_t *ifid_aton(char const *ifid_str, uint8_t *ifid); int rad_lockfd(int fd, int lock_len); int rad_lockfd_nonblock(int fd, int lock_len); int rad_unlockfd(int fd, int lock_len); +char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen); size_t fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen); size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen); uint32_t fr_strtoul(char const *value, char **end); diff --git a/src/lib/misc.c b/src/lib/misc.c index d4d87f4..84d1624 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -1053,7 +1053,6 @@ size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen) return i; } - /** Convert binary data to a hex string * * Ascii encoded hex string will not be prefixed with '0x' @@ -1080,7 +1079,26 @@ size_t fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen) return inlen * 2; } +/** Convert binary data to a hex string + * + * Ascii encoded hex string will not be prefixed with '0x' + * + * @param[in] ctx to alloc buffer in. + * @param[in] bin input. + * @param[in] inlen of bin input. + * @return length of data written to buffer. + */ +char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen) +{ + char *buff; + buff = talloc_array(ctx, char, (inlen << 2)); + if (!buff) return NULL; + + fr_bin2hex(buff, bin, inlen); + + return buff; +} /** Consume the integer (or hex) portion of a value string *