Merge data_blob_hex_string from Samba4.
authorGünther Deschner <gd@samba.org>
Fri, 25 Apr 2008 18:06:19 +0000 (20:06 +0200)
committerGünther Deschner <gd@samba.org>
Tue, 29 Apr 2008 18:22:01 +0000 (20:22 +0200)
Guenther
(This used to be commit 686d8939d90eab958d3a352fe53917ba7a17f39a)

source3/lib/data_blob.c

index daba17df14801ae8f4bbe6ef7656de665d6d7e4f..66c5daf363af67b5ffbb1f90281b178074bb1892 100644 (file)
@@ -156,3 +156,25 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length)
        data_blob_clear(&blob);
        return blob;
 }
+
+/**
+print the data_blob as hex string
+**/
+_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
+{
+       int i;
+       char *hex_string;
+
+       hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
+       if (!hex_string) {
+               return NULL;
+       }
+
+       for (i = 0; i < blob->length; i++)
+               slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]);
+
+       hex_string[(blob->length*2)] = '\0';
+       return hex_string;
+}
+
+