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/lib/libcrypto/asn1/a_string.c | |
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/lib/libcrypto/asn1/a_string.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_string.c | 61 |
1 files changed, 60 insertions, 1 deletions
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; |