source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/asn1/a_print.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.7 KB
Line 
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 <stdio.h>
11#include <ctype.h>
12#include "internal/cryptlib.h"
13#include <openssl/asn1.h>
14
15int ASN1_PRINTABLE_type(const unsigned char *s, int len)
16{
17 int c;
18 int ia5 = 0;
19 int t61 = 0;
20
21 if (len <= 0)
22 len = -1;
23 if (s == NULL)
24 return (V_ASN1_PRINTABLESTRING);
25
26 while ((*s) && (len-- != 0)) {
27 c = *(s++);
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 == '?')))
37 ia5 = 1;
38 if (c & 0x80)
39 t61 = 1;
40#else
41 if (!isalnum(c) && (c != ' ') && strchr("'()+,-./:=?", c) == NULL)
42 ia5 = 1;
43 if (os_toascii[c] & 0x80)
44 t61 = 1;
45#endif
46 }
47 if (t61)
48 return (V_ASN1_T61STRING);
49 if (ia5)
50 return (V_ASN1_IA5STRING);
51 return (V_ASN1_PRINTABLESTRING);
52}
53
54int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
55{
56 int i;
57 unsigned char *p;
58
59 if (s->type != V_ASN1_UNIVERSALSTRING)
60 return (0);
61 if ((s->length % 4) != 0)
62 return (0);
63 p = s->data;
64 for (i = 0; i < s->length; i += 4) {
65 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
66 break;
67 else
68 p += 4;
69 }
70 if (i < s->length)
71 return (0);
72 p = s->data;
73 for (i = 3; i < s->length; i += 4) {
74 *(p++) = s->data[i];
75 }
76 *(p) = '\0';
77 s->length /= 4;
78 s->type = ASN1_PRINTABLE_type(s->data, s->length);
79 return (1);
80}
81
82int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
83{
84 int i, n;
85 char buf[80];
86 const char *p;
87
88 if (v == NULL)
89 return (0);
90 n = 0;
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')))
95 buf[n] = '.';
96 else
97 buf[n] = p[i];
98 n++;
99 if (n >= 80) {
100 if (BIO_write(bp, buf, n) <= 0)
101 return (0);
102 n = 0;
103 }
104 }
105 if (n > 0)
106 if (BIO_write(bp, buf, n) <= 0)
107 return (0);
108 return (1);
109}
Note: See TracBrowser for help on using the repository browser.