]>
Commit | Line | Data |
---|---|---|
e0a65194 | 1 | #! /usr/bin/env perl |
c37b9479 | 2 | # Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. |
e0a65194 | 3 | # |
365a2d99 | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
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 | |
55707a36 | 8 | |
a657546f | 9 | use strict; |
c37b9479 RS |
10 | use FindBin; |
11 | use lib "$FindBin::Bin/../../util/perl"; | |
12 | use OpenSSL::copyright; | |
a657546f DSH |
13 | |
14 | my ($i, @arr); | |
15 | ||
16 | # Set up an array with the type of ASCII characters | |
17 | # Each set bit represents a character property. | |
18 | ||
19 | # RFC2253 character properties | |
20 | my $RFC2253_ESC = 1; # Character escaped with \ | |
21 | my $ESC_CTRL = 2; # Escaped control character | |
22 | # These are used with RFC1779 quoting using " | |
23 | my $NOESC_QUOTE = 8; # Not escaped if quoted | |
24 | my $PSTRING_CHAR = 0x10; # Valid PrintableString character | |
25 | my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character | |
26 | my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character | |
bc776510 | 27 | my $RFC2254_ESC = 0x400; # Character escaped \XX |
5bd5dcd4 DSH |
28 | my $HOST_ANY = 0x1000; # Valid hostname character anywhere in label |
29 | my $HOST_DOT = 0x2000; # Dot: hostname label separator | |
30 | my $HOST_HYPHEN = 0x4000; # Hyphen: not valid at start or end. | |
31 | my $HOST_WILD = 0x8000; # Wildcard character | |
a657546f DSH |
32 | |
33 | for($i = 0; $i < 128; $i++) { | |
34 | # Set the RFC2253 escape characters (control) | |
35 | $arr[$i] = 0; | |
36 | if(($i < 32) || ($i > 126)) { | |
37 | $arr[$i] |= $ESC_CTRL; | |
38 | } | |
39 | ||
40 | # Some PrintableString characters | |
41 | if( ( ( $i >= ord("a")) && ( $i <= ord("z")) ) | |
42 | || ( ( $i >= ord("A")) && ( $i <= ord("Z")) ) | |
43 | || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) { | |
5bd5dcd4 | 44 | $arr[$i] |= $PSTRING_CHAR | $HOST_ANY; |
a657546f DSH |
45 | } |
46 | } | |
47 | ||
48 | # Now setup the rest | |
49 | ||
50 | # Remaining RFC2253 escaped characters | |
51 | ||
52 | $arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC; | |
53 | $arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC; | |
54 | ||
55 | $arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC; | |
56 | $arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC; | |
57 | $arr[ord("\"")] |= $RFC2253_ESC; | |
58 | $arr[ord("\\")] |= $RFC2253_ESC; | |
59 | $arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC; | |
60 | $arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC; | |
61 | $arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC; | |
62 | ||
bc776510 RL |
63 | # Remaining RFC2254 characters |
64 | ||
65 | $arr[0] |= $RFC2254_ESC; | |
66 | $arr[ord("(")] |= $RFC2254_ESC; | |
67 | $arr[ord(")")] |= $RFC2254_ESC; | |
5bd5dcd4 | 68 | $arr[ord("*")] |= $RFC2254_ESC | $HOST_WILD; |
bc776510 RL |
69 | $arr[ord("\\")] |= $RFC2254_ESC; |
70 | ||
a657546f DSH |
71 | # Remaining PrintableString characters |
72 | ||
73 | $arr[ord(" ")] |= $PSTRING_CHAR; | |
74 | $arr[ord("'")] |= $PSTRING_CHAR; | |
75 | $arr[ord("(")] |= $PSTRING_CHAR; | |
76 | $arr[ord(")")] |= $PSTRING_CHAR; | |
77 | $arr[ord("+")] |= $PSTRING_CHAR; | |
78 | $arr[ord(",")] |= $PSTRING_CHAR; | |
5bd5dcd4 DSH |
79 | $arr[ord("-")] |= $PSTRING_CHAR | $HOST_HYPHEN; |
80 | $arr[ord(".")] |= $PSTRING_CHAR | $HOST_DOT; | |
a657546f DSH |
81 | $arr[ord("/")] |= $PSTRING_CHAR; |
82 | $arr[ord(":")] |= $PSTRING_CHAR; | |
83 | $arr[ord("=")] |= $PSTRING_CHAR; | |
84 | $arr[ord("?")] |= $PSTRING_CHAR; | |
85 | ||
86 | # Now generate the C code | |
87 | ||
339638b5 | 88 | # Year the file was generated. |
c37b9479 RS |
89 | my $YEAR = OpenSSL::copyright::year_of($0); |
90 | ||
a657546f | 91 | print <<EOF; |
e18cf66a RL |
92 | /* |
93 | * WARNING: do not edit! | |
94 | * Generated by crypto/asn1/charmap.pl | |
95 | * | |
97d37b85 | 96 | * Copyright 2000-$YEAR The OpenSSL Project Authors. All Rights Reserved. |
2039c421 | 97 | * |
365a2d99 | 98 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
e18cf66a RL |
99 | * this file except in compliance with the License. You can obtain a copy |
100 | * in the file LICENSE in the source distribution or at | |
101 | * https://www.openssl.org/source/license.html | |
102 | */ | |
103 | ||
5bd5dcd4 DSH |
104 | #define CHARTYPE_HOST_ANY $HOST_ANY |
105 | #define CHARTYPE_HOST_DOT $HOST_DOT | |
106 | #define CHARTYPE_HOST_HYPHEN $HOST_HYPHEN | |
107 | #define CHARTYPE_HOST_WILD $HOST_WILD | |
108 | ||
e18cf66a | 109 | /* |
a657546f DSH |
110 | * Mask of various character properties |
111 | */ | |
112 | ||
bc776510 | 113 | static const unsigned short char_type[] = { |
a657546f DSH |
114 | EOF |
115 | ||
e18cf66a | 116 | print " "; |
a657546f | 117 | for($i = 0; $i < 128; $i++) { |
5bd5dcd4 DSH |
118 | print("\n ") if($i && (($i % 12) == 0)); |
119 | printf(" %4d", $arr[$i]); | |
a657546f DSH |
120 | print(",") if ($i != 127); |
121 | } | |
e18cf66a | 122 | print("\n};\n"); |
a657546f | 123 |