diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/data_blob.c | 19 | ||||
-rw-r--r-- | lib/util/data_blob.h | 7 | ||||
-rw-r--r-- | lib/util/tests/data_blob.c | 3 |
3 files changed, 26 insertions, 3 deletions
diff --git a/lib/util/data_blob.c b/lib/util/data_blob.c index 825d8cf88c..6e7557f8ef 100644 --- a/lib/util/data_blob.c +++ b/lib/util/data_blob.c @@ -153,7 +153,7 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2) /** print the data_blob as hex string **/ -_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) +_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) { int i; char *hex_string; @@ -173,6 +173,23 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) return hex_string; } +_PUBLIC_ char *data_blob_hex_string_upper(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; +} + /** useful for constructing data blobs in test suites, while avoiding const warnings diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h index ffde51cf33..c294533960 100644 --- a/lib/util/data_blob.h +++ b/lib/util/data_blob.h @@ -96,7 +96,12 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2); /** print the data_blob as hex string **/ -_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob); +_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob); + +/** +print the data_blob as hex string +**/ +_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob); /** useful for constructing data blobs in test suites, while diff --git a/lib/util/tests/data_blob.c b/lib/util/tests/data_blob.c index f0b02b8d17..53330a4afd 100644 --- a/lib/util/tests/data_blob.c +++ b/lib/util/tests/data_blob.c @@ -78,7 +78,8 @@ static bool test_cmp(struct torture_context *tctx) static bool test_hex_string(struct torture_context *tctx) { DATA_BLOB a = data_blob_string_const("\xC\xA\xF\xE"); - torture_assert_str_equal(tctx, data_blob_hex_string(tctx, &a), "0c0a0f0e", "hex string"); + torture_assert_str_equal(tctx, data_blob_hex_string_lower(tctx, &a), "0c0a0f0e", "hex string"); + torture_assert_str_equal(tctx, data_blob_hex_string_upper(tctx, &a), "0C0A0F0E", "hex string"); return true; } |