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