2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
12 #include "internal/cryptlib.h"
13 #include <openssl/asn1.h>
15 int ASN1_PRINTABLE_type(const unsigned char *s, int len)
24 return (V_ASN1_PRINTABLESTRING);
26 while ((*s) && (len-- != 0)) {
28 #ifndef CHARSET_EBCDIC
29 if (!(((c >= 'a') && (c <= 'z')) ||
30 ((c >= 'A') && (c <= 'Z')) ||
31 ((c >= '0') && (c <= '9')) ||
32 (c == ' ') || (c == '\'') ||
33 (c == '(') || (c == ')') ||
34 (c == '+') || (c == ',') ||
35 (c == '-') || (c == '.') ||
36 (c == '/') || (c == ':') || (c == '=') || (c == '?')))
41 if (!isalnum(c) && (c != ' ') && strchr("'()+,-./:=?", c) == NULL)
43 if (os_toascii[c] & 0x80)
48 return (V_ASN1_T61STRING);
50 return (V_ASN1_IA5STRING);
51 return (V_ASN1_PRINTABLESTRING);
54 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
59 if (s->type != V_ASN1_UNIVERSALSTRING)
61 if ((s->length % 4) != 0)
64 for (i = 0; i < s->length; i += 4) {
65 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
73 for (i = 3; i < s->length; i += 4) {
78 s->type = ASN1_PRINTABLE_type(s->data, s->length);
82 int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
91 p = (const char *)v->data;
92 for (i = 0; i < v->length; i++) {
93 if ((p[i] > '~') || ((p[i] < ' ') &&
94 (p[i] != '\n') && (p[i] != '\r')))
100 if (BIO_write(bp, buf, n) <= 0)
106 if (BIO_write(bp, buf, n) <= 0)