From: jsing Date: Sat, 25 Dec 2021 12:11:57 +0000 (+0000) Subject: Move more ASN1_STRING_* functions to a_string.c. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=aebda5a73ed1e0297a22c349b07dbaecee6ee51b;p=openbsd Move more ASN1_STRING_* functions to a_string.c. No functional change. --- 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 #include +#include "asn1_locl.h" + ASN1_STRING * ASN1_STRING_new(void) { @@ -209,6 +211,63 @@ ASN1_STRING_get0_data(const ASN1_STRING *x) return (x->data); } +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) { 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. * @@ -351,36 +351,6 @@ X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig) return 1; } -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) {