• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <openssl/asn1.h>
11 
12 #include <openssl/bio.h>
13 
i2a_ASN1_STRING(BIO * bp,const ASN1_STRING * a,int type)14 int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) {
15   int i, n = 0;
16   static const char *h = "0123456789ABCDEF";
17   char buf[2];
18 
19   if (a == NULL) {
20     return 0;
21   }
22 
23   if (a->length == 0) {
24     if (BIO_write(bp, "0", 1) != 1) {
25       goto err;
26     }
27     n = 1;
28   } else {
29     for (i = 0; i < a->length; i++) {
30       if ((i != 0) && (i % 35 == 0)) {
31         if (BIO_write(bp, "\\\n", 2) != 2) {
32           goto err;
33         }
34         n += 2;
35       }
36       buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
37       buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
38       if (BIO_write(bp, buf, 2) != 2) {
39         goto err;
40       }
41       n += 2;
42     }
43   }
44   return n;
45 err:
46   return -1;
47 }
48