Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/asn1/f_string.c

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <openssl/asn1.h>
5
6 #include <openssl/bio.h>
7
8 int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) {
9 int i, n = 0;
10 static const char *h = "0123456789ABCDEF";
11 char buf[2];
12
13 if (a == NULL) {
14 return 0;
15 }
16
17 if (a->length == 0) {
18 if (BIO_write(bp, "0", 1) != 1) {
19 goto err;
20 }
21 n = 1;
22 } else {
23 for (i = 0; i < a->length; i++) {
24 if ((i != 0) && (i % 35 == 0)) {
25 if (BIO_write(bp, "\\\n", 2) != 2) {
26 goto err;
27 }
28 n += 2;
29 }
30 buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
31 buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
32 if (BIO_write(bp, buf, 2) != 2) {
33 goto err;
34 }
35 n += 2;
36 }
37 }
38 return n;
39 err:
40 return -1;
41 }