/src/openssl30/crypto/asn1/a_print.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the Apache License 2.0 (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 <stdio.h> | 
| 11 |  | #include "crypto/ctype.h" | 
| 12 |  | #include "internal/cryptlib.h" | 
| 13 |  | #include <openssl/asn1.h> | 
| 14 |  |  | 
| 15 |  | int ASN1_PRINTABLE_type(const unsigned char *s, int len) | 
| 16 | 0 | { | 
| 17 | 0 |     int c; | 
| 18 | 0 |     int ia5 = 0; | 
| 19 | 0 |     int t61 = 0; | 
| 20 |  | 
 | 
| 21 | 0 |     if (s == NULL) | 
| 22 | 0 |         return V_ASN1_PRINTABLESTRING; | 
| 23 |  |  | 
| 24 | 0 |     if (len < 0) | 
| 25 | 0 |         len = strlen((const char *)s); | 
| 26 |  | 
 | 
| 27 | 0 |     while (len-- > 0) { | 
| 28 | 0 |         c = *(s++); | 
| 29 | 0 |         if (!ossl_isasn1print(c)) | 
| 30 | 0 |             ia5 = 1; | 
| 31 | 0 |         if (!ossl_isascii(c)) | 
| 32 | 0 |             t61 = 1; | 
| 33 | 0 |     } | 
| 34 | 0 |     if (t61) | 
| 35 | 0 |         return V_ASN1_T61STRING; | 
| 36 | 0 |     if (ia5) | 
| 37 | 0 |         return V_ASN1_IA5STRING; | 
| 38 | 0 |     return V_ASN1_PRINTABLESTRING; | 
| 39 | 0 | } | 
| 40 |  |  | 
| 41 |  | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | 
| 42 | 0 | { | 
| 43 | 0 |     int i; | 
| 44 | 0 |     unsigned char *p; | 
| 45 |  | 
 | 
| 46 | 0 |     if (s->type != V_ASN1_UNIVERSALSTRING) | 
| 47 | 0 |         return 0; | 
| 48 | 0 |     if ((s->length % 4) != 0) | 
| 49 | 0 |         return 0; | 
| 50 | 0 |     p = s->data; | 
| 51 | 0 |     for (i = 0; i < s->length; i += 4) { | 
| 52 | 0 |         if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | 
| 53 | 0 |             break; | 
| 54 | 0 |         else | 
| 55 | 0 |             p += 4; | 
| 56 | 0 |     } | 
| 57 | 0 |     if (i < s->length) | 
| 58 | 0 |         return 0; | 
| 59 | 0 |     p = s->data; | 
| 60 | 0 |     for (i = 3; i < s->length; i += 4) { | 
| 61 | 0 |         *(p++) = s->data[i]; | 
| 62 | 0 |     } | 
| 63 | 0 |     *(p) = '\0'; | 
| 64 | 0 |     s->length /= 4; | 
| 65 | 0 |     s->type = ASN1_PRINTABLE_type(s->data, s->length); | 
| 66 | 0 |     return 1; | 
| 67 | 0 | } | 
| 68 |  |  | 
| 69 |  | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | 
| 70 | 491k | { | 
| 71 | 491k |     int i, n; | 
| 72 | 491k |     char buf[80]; | 
| 73 | 491k |     const char *p; | 
| 74 |  |  | 
| 75 | 491k |     if (v == NULL) | 
| 76 | 0 |         return 0; | 
| 77 | 491k |     n = 0; | 
| 78 | 491k |     p = (const char *)v->data; | 
| 79 | 20.8M |     for (i = 0; i < v->length; i++) { | 
| 80 | 20.3M |         if ((p[i] > '~') || ((p[i] < ' ') && | 
| 81 | 20.2M |                              (p[i] != '\n') && (p[i] != '\r'))) | 
| 82 | 11.7M |             buf[n] = '.'; | 
| 83 | 8.52M |         else | 
| 84 | 8.52M |             buf[n] = p[i]; | 
| 85 | 20.3M |         n++; | 
| 86 | 20.3M |         if (n >= 80) { | 
| 87 | 125k |             if (BIO_write(bp, buf, n) <= 0) | 
| 88 | 0 |                 return 0; | 
| 89 | 125k |             n = 0; | 
| 90 | 125k |         } | 
| 91 | 20.3M |     } | 
| 92 | 491k |     if (n > 0) | 
| 93 | 436k |         if (BIO_write(bp, buf, n) <= 0) | 
| 94 | 0 |             return 0; | 
| 95 | 491k |     return 1; | 
| 96 | 491k | } |