summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan M. Wilbur <jonathan@wilbur.space>2024-09-13 01:22:42 +0200
committerTomas Mraz <tomas@openssl.org>2024-11-13 11:53:34 +0100
commit1f7d2a28877dffdaf607a6fdcc5fcc5f5e030b1e (patch)
tree311055882cf43cee0b481b67e67187755ef9fb46
parenttest: the attributeDescriptor X.509v3 extension (diff)
downloadopenssl-1f7d2a28877dffdaf607a6fdcc5fcc5f5e030b1e.tar.xz
openssl-1f7d2a28877dffdaf607a6fdcc5fcc5f5e030b1e.zip
feat: define and use ossl_bio_print_hex
Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/25429)
-rw-r--r--crypto/x509/v3_attrdesc.c24
-rw-r--r--crypto/x509/v3_utl.c17
-rw-r--r--crypto/x509/x_attrib.c27
-rw-r--r--doc/internal/man3/ossl_bio_print_hex.pod32
-rw-r--r--include/crypto/x509.h1
5 files changed, 58 insertions, 43 deletions
diff --git a/crypto/x509/v3_attrdesc.c b/crypto/x509/v3_attrdesc.c
index 85509fc402..45958e9aff 100644
--- a/crypto/x509/v3_attrdesc.c
+++ b/crypto/x509/v3_attrdesc.c
@@ -46,24 +46,6 @@ IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX_POINTER)
IMPLEMENT_ASN1_FUNCTIONS(OSSL_PRIVILEGE_POLICY_ID)
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_DESCRIPTOR)
-/* Copied from x_attrib.c */
-static int print_hex(BIO *out, unsigned char *buf, int len)
-{
- int result = 1;
- char *hexbuf;
-
- if (len == 0)
- return 1;
-
- hexbuf = OPENSSL_buf2hexstr(buf, len);
- if (hexbuf == NULL)
- return 0;
- result = BIO_puts(out, hexbuf) > 0;
-
- OPENSSL_free(hexbuf);
- return result;
-}
-
static int i2r_HASH(X509V3_EXT_METHOD *method,
OSSL_HASH *hash,
BIO *out, int indent)
@@ -85,7 +67,7 @@ static int i2r_HASH(X509V3_EXT_METHOD *method,
}
if (BIO_printf(out, "%*sHash Value: ", indent, "") <= 0)
return 0;
- return print_hex(out, hash->hashValue->data, hash->hashValue->length);
+ return ossl_bio_print_hex(out, hash->hashValue->data, hash->hashValue->length);
}
static int i2r_INFO_SYNTAX_POINTER(X509V3_EXT_METHOD *method,
@@ -112,7 +94,7 @@ static int i2r_OSSL_INFO_SYNTAX(X509V3_EXT_METHOD *method,
BIO *out, int indent)
{
switch (info->type) {
- case (OSSL_INFO_SYNTAX_TYPE_CONTENT):
+ case OSSL_INFO_SYNTAX_TYPE_CONTENT:
if (BIO_printf(out, "%*sContent: ", indent, "") <= 0)
return 0;
if (BIO_printf(out, "%.*s", info->choice.content->length, info->choice.content->data) <= 0)
@@ -120,7 +102,7 @@ static int i2r_OSSL_INFO_SYNTAX(X509V3_EXT_METHOD *method,
if (BIO_puts(out, "\n") <= 0)
return 0;
return 1;
- case (OSSL_INFO_SYNTAX_TYPE_POINTER):
+ case OSSL_INFO_SYNTAX_TYPE_POINTER:
if (BIO_printf(out, "%*sPointer:\n", indent, "") <= 0)
return 0;
return i2r_INFO_SYNTAX_POINTER(method, info->choice.pointer, out, indent + 4);
diff --git a/crypto/x509/v3_utl.c b/crypto/x509/v3_utl.c
index 40eef9eb31..60aa31a7c7 100644
--- a/crypto/x509/v3_utl.c
+++ b/crypto/x509/v3_utl.c
@@ -1434,3 +1434,20 @@ int OSSL_GENERAL_NAMES_print(BIO *out, GENERAL_NAMES *gens, int indent)
}
return 1;
}
+
+int ossl_bio_print_hex(BIO *out, unsigned char *buf, int len)
+{
+ int result;
+ char *hexbuf;
+
+ if (len == 0)
+ return 1;
+
+ hexbuf = OPENSSL_buf2hexstr(buf, len);
+ if (hexbuf == NULL)
+ return 0;
+ result = BIO_puts(out, hexbuf) > 0;
+
+ OPENSSL_free(hexbuf);
+ return result;
+}
diff --git a/crypto/x509/x_attrib.c b/crypto/x509/x_attrib.c
index 310bef2580..0bae13dd73 100644
--- a/crypto/x509/x_attrib.c
+++ b/crypto/x509/x_attrib.c
@@ -58,23 +58,6 @@ X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
return NULL;
}
-static int print_hex(BIO *out, unsigned char *buf, int len)
-{
- int result = 1;
- char *hexbuf;
-
- if (len == 0)
- return 1;
-
- hexbuf = OPENSSL_buf2hexstr(buf, len);
- if (hexbuf == NULL)
- return 0;
- result = BIO_puts(out, hexbuf) > 0;
-
- OPENSSL_free(hexbuf);
- return result;
-}
-
static int print_oid(BIO *out, const ASN1_OBJECT *oid) {
const char *ln;
char objbuf[80];
@@ -116,20 +99,20 @@ int ossl_print_attribute_value(BIO *out,
return BIO_printf(out, "%lld", (long long int)int_val) > 0;
}
str = av->value.integer;
- return print_hex(out, str->data, str->length);
+ return ossl_bio_print_hex(out, str->data, str->length);
case V_ASN1_BIT_STRING:
if (BIO_printf(out, "%*s", indent, "") < 0)
return 0;
- return print_hex(out, av->value.bit_string->data,
- av->value.bit_string->length);
+ return ossl_bio_print_hex(out, av->value.bit_string->data,
+ av->value.bit_string->length);
case V_ASN1_OCTET_STRING:
case V_ASN1_VIDEOTEXSTRING:
if (BIO_printf(out, "%*s", indent, "") < 0)
return 0;
- return print_hex(out, av->value.octet_string->data,
- av->value.octet_string->length);
+ return ossl_bio_print_hex(out, av->value.octet_string->data,
+ av->value.octet_string->length);
case V_ASN1_NULL:
return BIO_printf(out, "%*sNULL", indent, "") >= 4;
diff --git a/doc/internal/man3/ossl_bio_print_hex.pod b/doc/internal/man3/ossl_bio_print_hex.pod
new file mode 100644
index 0000000000..6607e6d750
--- /dev/null
+++ b/doc/internal/man3/ossl_bio_print_hex.pod
@@ -0,0 +1,32 @@
+=pod
+
+=head1 NAME
+
+ossl_bio_print_hex
+- Print a hexdump of a binary input
+
+=head1 SYNOPSIS
+
+ #include <crypto/x509.h>
+
+ int ossl_bio_print_hex(BIO *out, unsigned char *buf, int len);
+
+=head1 DESCRIPTION
+
+This function prints a hexdump-like hexadecimal output to I<out> from a binary
+input I<buf> that is I<len> bytes in length.
+
+=head1 RETURN VALUES
+
+Returns 1 if it succeeds in printing, and 0 if it failed.
+
+=head1 COPYRIGHT
+
+Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
+
+Licensed under the Apache License 2.0 (the "License"). You may not use
+this file except in compliance with the License. You can obtain a copy
+in the file LICENSE in the source distribution or at
+L<https://www.openssl.org/source/license.html>.
+
+=cut
diff --git a/include/crypto/x509.h b/include/crypto/x509.h
index 616265f5b2..e6ebae3914 100644
--- a/include/crypto/x509.h
+++ b/include/crypto/x509.h
@@ -393,5 +393,6 @@ int ossl_print_attribute_value(BIO *out,
int indent);
int ossl_serial_number_print(BIO *out, const ASN1_INTEGER *bs, int indent);
+int ossl_bio_print_hex(BIO *out, unsigned char *buf, int len);
#endif /* OSSL_CRYPTO_X509_H */