Add fr_abin2hex
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 25 Jun 2014 16:39:42 +0000 (17:39 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 25 Jun 2014 16:43:02 +0000 (17:43 +0100)
src/include/libradius.h
src/lib/misc.c

index bc2bb87..747e846 100644 (file)
@@ -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);
index d4d87f4..84d1624 100644 (file)
@@ -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
  *