diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2021-12-25 12:11:58 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2021-12-25 12:11:58 +0000 |
commit | 9b40b3aa6d77c8ddaa6d8b7e080fd3e5761ad0fb (patch) | |
tree | 5b1ae4b4c67e9660c7763f135f63e58c17e64c6b /lib/libcrypto | |
parent | 75d2bf289916c98a0594949d698d7c8625fdf0cf (diff) |
Move more ASN1_STRING_* functions to a_string.c.
No functional change.
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/asn1/a_strex.c | 29 | ||||
-rw-r--r-- | lib/libcrypto/asn1/a_string.c | 61 | ||||
-rw-r--r-- | lib/libcrypto/asn1/t_x509.c | 32 |
3 files changed, 62 insertions, 60 deletions
diff --git a/lib/libcrypto/asn1/a_strex.c b/lib/libcrypto/asn1/a_strex.c index 61672d29a44..848d1bffd73 100644 --- a/lib/libcrypto/asn1/a_strex.c +++ b/lib/libcrypto/asn1/a_strex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_strex.c,v 1.30 2021/12/14 17:35:21 jsing Exp $ */ +/* $OpenBSD: a_strex.c,v 1.31 2021/12/25 12:11:57 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -599,30 +599,3 @@ ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags) { return do_print_ex(send_fp_chars, fp, flags, str); } - -/* Utility function: convert any string type to UTF8, returns number of bytes - * in output string or a negative error code - */ - -int -ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) -{ - ASN1_STRING stmp, *str = &stmp; - int mbflag, ret; - - if (!in) - return -1; - - if ((mbflag = asn1_tag2charwidth(in->type)) == -1) - return -1; - mbflag |= MBSTRING_FLAG; - - stmp.data = NULL; - stmp.length = 0; - ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, - B_ASN1_UTF8STRING); - if (ret < 0) - return ret; - *out = stmp.data; - return stmp.length; -} diff --git a/lib/libcrypto/asn1/a_string.c b/lib/libcrypto/asn1/a_string.c index e7e75ff9d3f..7a9eabe6c60 100644 --- a/lib/libcrypto/asn1/a_string.c +++ b/lib/libcrypto/asn1/a_string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_string.c,v 1.2 2021/12/24 14:12:26 jsing Exp $ */ +/* $OpenBSD: a_string.c,v 1.3 2021/12/25 12:11:57 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -63,6 +63,8 @@ #include <openssl/buffer.h> #include <openssl/err.h> +#include "asn1_locl.h" + ASN1_STRING * ASN1_STRING_new(void) { @@ -210,6 +212,63 @@ ASN1_STRING_get0_data(const ASN1_STRING *x) } int +ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) +{ + int i, n; + char buf[80]; + const char *p; + + if (v == NULL) + return (0); + n = 0; + p = (const char *)v->data; + for (i = 0; i < v->length; i++) { + if ((p[i] > '~') || ((p[i] < ' ') && + (p[i] != '\n') && (p[i] != '\r'))) + buf[n] = '.'; + else + buf[n] = p[i]; + n++; + if (n >= 80) { + if (BIO_write(bp, buf, n) <= 0) + return (0); + n = 0; + } + } + if (n > 0) + if (BIO_write(bp, buf, n) <= 0) + return (0); + return (1); +} + +/* + * Utility function: convert any string type to UTF8, returns number of bytes + * in output string or a negative error code + */ +int +ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) +{ + ASN1_STRING stmp, *str = &stmp; + int mbflag, ret; + + if (!in) + return -1; + + if ((mbflag = asn1_tag2charwidth(in->type)) == -1) + return -1; + mbflag |= MBSTRING_FLAG; + + stmp.data = NULL; + stmp.length = 0; + ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, + B_ASN1_UTF8STRING); + if (ret < 0) + return ret; + *out = stmp.data; + return stmp.length; +} + +int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) { int i, n = 0; diff --git a/lib/libcrypto/asn1/t_x509.c b/lib/libcrypto/asn1/t_x509.c index d1655a17850..ff7871cd060 100644 --- a/lib/libcrypto/asn1/t_x509.c +++ b/lib/libcrypto/asn1/t_x509.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_x509.c,v 1.35 2021/11/01 20:53:08 tb Exp $ */ +/* $OpenBSD: t_x509.c,v 1.36 2021/12/25 12:11:57 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -352,36 +352,6 @@ X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig) } int -ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) -{ - int i, n; - char buf[80]; - const char *p; - - if (v == NULL) - return (0); - n = 0; - p = (const char *)v->data; - for (i = 0; i < v->length; i++) { - if ((p[i] > '~') || ((p[i] < ' ') && - (p[i] != '\n') && (p[i] != '\r'))) - buf[n] = '.'; - else - buf[n] = p[i]; - n++; - if (n >= 80) { - if (BIO_write(bp, buf, n) <= 0) - return (0); - n = 0; - } - } - if (n > 0) - if (BIO_write(bp, buf, n) <= 0) - return (0); - return (1); -} - -int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) { if (tm->type == V_ASN1_UTCTIME) |