]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_print.c
328e0abcc510680ecac3875404548ad3d86d5020
2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "crypto/ctype.h"
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 if (!ossl_isasn1print(c
))
34 return V_ASN1_T61STRING
;
36 return V_ASN1_IA5STRING
;
37 return V_ASN1_PRINTABLESTRING
;
40 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING
*s
)
45 if (s
->type
!= V_ASN1_UNIVERSALSTRING
)
47 if ((s
->length
% 4) != 0)
50 for (i
= 0; i
< s
->length
; i
+= 4) {
51 if ((p
[0] != '\0') || (p
[1] != '\0') || (p
[2] != '\0'))
59 for (i
= 3; i
< s
->length
; i
+= 4) {
64 s
->type
= ASN1_PRINTABLE_type(s
->data
, s
->length
);
68 int ASN1_STRING_print(BIO
*bp
, const ASN1_STRING
*v
)
77 p
= (const char *)v
->data
;
78 for (i
= 0; i
< v
->length
; i
++) {
79 if ((p
[i
] > '~') || ((p
[i
] < ' ') &&
80 (p
[i
] != '\n') && (p
[i
] != '\r')))
86 if (BIO_write(bp
, buf
, n
) <= 0)
92 if (BIO_write(bp
, buf
, n
) <= 0)