diff options
author | jsing <> | 2021-12-25 12:11:57 +0000 |
---|---|---|
committer | jsing <> | 2021-12-25 12:11:57 +0000 |
commit | 82039a0b66d9e62c5617556d457e9612bfc56e8d (patch) | |
tree | 31241539cb67295a30e1674c67e5bba1b76e248e /src | |
parent | 346d30a52f494d9f2e76e352a6ba8ca2ebdcf62f (diff) | |
download | openbsd-82039a0b66d9e62c5617556d457e9612bfc56e8d.tar.gz openbsd-82039a0b66d9e62c5617556d457e9612bfc56e8d.tar.bz2 openbsd-82039a0b66d9e62c5617556d457e9612bfc56e8d.zip |
Move more ASN1_STRING_* functions to a_string.c.
No functional change.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/a_strex.c | 29 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/a_string.c | 61 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/t_x509.c | 32 |
3 files changed, 62 insertions, 60 deletions
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index 61672d29a4..848d1bffd7 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_strex.c,v 1.30 2021/12/14 17:35:21 jsing Exp $ */ | 1 | /* $OpenBSD: a_strex.c,v 1.31 2021/12/25 12:11:57 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -599,30 +599,3 @@ ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags) | |||
599 | { | 599 | { |
600 | return do_print_ex(send_fp_chars, fp, flags, str); | 600 | return do_print_ex(send_fp_chars, fp, flags, str); |
601 | } | 601 | } |
602 | |||
603 | /* Utility function: convert any string type to UTF8, returns number of bytes | ||
604 | * in output string or a negative error code | ||
605 | */ | ||
606 | |||
607 | int | ||
608 | ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) | ||
609 | { | ||
610 | ASN1_STRING stmp, *str = &stmp; | ||
611 | int mbflag, ret; | ||
612 | |||
613 | if (!in) | ||
614 | return -1; | ||
615 | |||
616 | if ((mbflag = asn1_tag2charwidth(in->type)) == -1) | ||
617 | return -1; | ||
618 | mbflag |= MBSTRING_FLAG; | ||
619 | |||
620 | stmp.data = NULL; | ||
621 | stmp.length = 0; | ||
622 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, | ||
623 | B_ASN1_UTF8STRING); | ||
624 | if (ret < 0) | ||
625 | return ret; | ||
626 | *out = stmp.data; | ||
627 | return stmp.length; | ||
628 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_string.c b/src/lib/libcrypto/asn1/a_string.c index e7e75ff9d3..7a9eabe6c6 100644 --- a/src/lib/libcrypto/asn1/a_string.c +++ b/src/lib/libcrypto/asn1/a_string.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_string.c,v 1.2 2021/12/24 14:12:26 jsing Exp $ */ | 1 | /* $OpenBSD: a_string.c,v 1.3 2021/12/25 12:11:57 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -63,6 +63,8 @@ | |||
63 | #include <openssl/buffer.h> | 63 | #include <openssl/buffer.h> |
64 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
65 | 65 | ||
66 | #include "asn1_locl.h" | ||
67 | |||
66 | ASN1_STRING * | 68 | ASN1_STRING * |
67 | ASN1_STRING_new(void) | 69 | ASN1_STRING_new(void) |
68 | { | 70 | { |
@@ -210,6 +212,63 @@ ASN1_STRING_get0_data(const ASN1_STRING *x) | |||
210 | } | 212 | } |
211 | 213 | ||
212 | int | 214 | int |
215 | ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | ||
216 | { | ||
217 | int i, n; | ||
218 | char buf[80]; | ||
219 | const char *p; | ||
220 | |||
221 | if (v == NULL) | ||
222 | return (0); | ||
223 | n = 0; | ||
224 | p = (const char *)v->data; | ||
225 | for (i = 0; i < v->length; i++) { | ||
226 | if ((p[i] > '~') || ((p[i] < ' ') && | ||
227 | (p[i] != '\n') && (p[i] != '\r'))) | ||
228 | buf[n] = '.'; | ||
229 | else | ||
230 | buf[n] = p[i]; | ||
231 | n++; | ||
232 | if (n >= 80) { | ||
233 | if (BIO_write(bp, buf, n) <= 0) | ||
234 | return (0); | ||
235 | n = 0; | ||
236 | } | ||
237 | } | ||
238 | if (n > 0) | ||
239 | if (BIO_write(bp, buf, n) <= 0) | ||
240 | return (0); | ||
241 | return (1); | ||
242 | } | ||
243 | |||
244 | /* | ||
245 | * Utility function: convert any string type to UTF8, returns number of bytes | ||
246 | * in output string or a negative error code | ||
247 | */ | ||
248 | int | ||
249 | ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) | ||
250 | { | ||
251 | ASN1_STRING stmp, *str = &stmp; | ||
252 | int mbflag, ret; | ||
253 | |||
254 | if (!in) | ||
255 | return -1; | ||
256 | |||
257 | if ((mbflag = asn1_tag2charwidth(in->type)) == -1) | ||
258 | return -1; | ||
259 | mbflag |= MBSTRING_FLAG; | ||
260 | |||
261 | stmp.data = NULL; | ||
262 | stmp.length = 0; | ||
263 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, | ||
264 | B_ASN1_UTF8STRING); | ||
265 | if (ret < 0) | ||
266 | return ret; | ||
267 | *out = stmp.data; | ||
268 | return stmp.length; | ||
269 | } | ||
270 | |||
271 | int | ||
213 | i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) | 272 | i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) |
214 | { | 273 | { |
215 | int i, n = 0; | 274 | int i, n = 0; |
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index d1655a1785..ff7871cd06 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t_x509.c,v 1.35 2021/11/01 20:53:08 tb Exp $ */ | 1 | /* $OpenBSD: t_x509.c,v 1.36 2021/12/25 12:11:57 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -352,36 +352,6 @@ X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig) | |||
352 | } | 352 | } |
353 | 353 | ||
354 | int | 354 | int |
355 | ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | ||
356 | { | ||
357 | int i, n; | ||
358 | char buf[80]; | ||
359 | const char *p; | ||
360 | |||
361 | if (v == NULL) | ||
362 | return (0); | ||
363 | n = 0; | ||
364 | p = (const char *)v->data; | ||
365 | for (i = 0; i < v->length; i++) { | ||
366 | if ((p[i] > '~') || ((p[i] < ' ') && | ||
367 | (p[i] != '\n') && (p[i] != '\r'))) | ||
368 | buf[n] = '.'; | ||
369 | else | ||
370 | buf[n] = p[i]; | ||
371 | n++; | ||
372 | if (n >= 80) { | ||
373 | if (BIO_write(bp, buf, n) <= 0) | ||
374 | return (0); | ||
375 | n = 0; | ||
376 | } | ||
377 | } | ||
378 | if (n > 0) | ||
379 | if (BIO_write(bp, buf, n) <= 0) | ||
380 | return (0); | ||
381 | return (1); | ||
382 | } | ||
383 | |||
384 | int | ||
385 | ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | 355 | ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) |
386 | { | 356 | { |
387 | if (tm->type == V_ASN1_UTCTIME) | 357 | if (tm->type == V_ASN1_UTCTIME) |