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