1e1051a39Sopenharmony_ci#! /usr/bin/env perl
2e1051a39Sopenharmony_ci# Copyright 1995-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 warnings;
11e1051a39Sopenharmony_ciuse FindBin;
12e1051a39Sopenharmony_ciuse lib "$FindBin::Bin/../../util/perl";
13e1051a39Sopenharmony_ciuse OpenSSL::copyright;
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_cimy $NUMBER      = 0x0001;
16e1051a39Sopenharmony_cimy $UPPER       = 0x0002;
17e1051a39Sopenharmony_cimy $LOWER       = 0x0004;
18e1051a39Sopenharmony_cimy $UNDER       = 0x0100;
19e1051a39Sopenharmony_cimy $PUNCTUATION = 0x0200;
20e1051a39Sopenharmony_cimy $WS          = 0x0010;
21e1051a39Sopenharmony_cimy $ESC         = 0x0020;
22e1051a39Sopenharmony_cimy $QUOTE       = 0x0040;
23e1051a39Sopenharmony_cimy $DQUOTE      = 0x0400;
24e1051a39Sopenharmony_cimy $COMMENT     = 0x0080;
25e1051a39Sopenharmony_cimy $FCOMMENT    = 0x0800;
26e1051a39Sopenharmony_cimy $DOLLAR      = 0x1000;
27e1051a39Sopenharmony_cimy $EOF         = 0x0008;
28e1051a39Sopenharmony_cimy @V_def;
29e1051a39Sopenharmony_cimy @V_w32;
30e1051a39Sopenharmony_ci
31e1051a39Sopenharmony_cimy $v;
32e1051a39Sopenharmony_cimy $c;
33e1051a39Sopenharmony_ciforeach (0 .. 127) {
34e1051a39Sopenharmony_ci    $c = sprintf("%c", $_);
35e1051a39Sopenharmony_ci    $v = 0;
36e1051a39Sopenharmony_ci    $v |= $NUMBER      if $c =~ /[0-9]/;
37e1051a39Sopenharmony_ci    $v |= $UPPER       if $c =~ /[A-Z]/;
38e1051a39Sopenharmony_ci    $v |= $LOWER       if $c =~ /[a-z]/;
39e1051a39Sopenharmony_ci    $v |= $UNDER       if $c =~ /_/;
40e1051a39Sopenharmony_ci    $v |= $PUNCTUATION if $c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/;
41e1051a39Sopenharmony_ci    $v |= $WS          if $c =~ /[ \t\r\n]/;
42e1051a39Sopenharmony_ci    $v |= $ESC         if $c =~ /\\/;
43e1051a39Sopenharmony_ci    $v |= $QUOTE       if $c =~ /['`"]/;         # for emacs: "`'
44e1051a39Sopenharmony_ci    $v |= $COMMENT     if $c =~ /\#/;
45e1051a39Sopenharmony_ci    $v |= $DOLLAR      if $c eq '$';
46e1051a39Sopenharmony_ci    $v |= $EOF         if $c =~ /\0/;
47e1051a39Sopenharmony_ci    push(@V_def, $v);
48e1051a39Sopenharmony_ci
49e1051a39Sopenharmony_ci    $v = 0;
50e1051a39Sopenharmony_ci    $v |= $NUMBER      if $c =~ /[0-9]/;
51e1051a39Sopenharmony_ci    $v |= $UPPER       if $c =~ /[A-Z]/;
52e1051a39Sopenharmony_ci    $v |= $LOWER       if $c =~ /[a-z]/;
53e1051a39Sopenharmony_ci    $v |= $UNDER       if $c =~ /_/;
54e1051a39Sopenharmony_ci    $v |= $PUNCTUATION if $c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/;
55e1051a39Sopenharmony_ci    $v |= $WS          if $c =~ /[ \t\r\n]/;
56e1051a39Sopenharmony_ci    $v |= $DQUOTE      if $c =~ /["]/;           # for emacs: "
57e1051a39Sopenharmony_ci    $v |= $FCOMMENT    if $c =~ /;/;
58e1051a39Sopenharmony_ci    $v |= $DOLLAR      if $c eq '$';
59e1051a39Sopenharmony_ci    $v |= $EOF         if $c =~ /\0/;
60e1051a39Sopenharmony_ci    push(@V_w32, $v);
61e1051a39Sopenharmony_ci}
62e1051a39Sopenharmony_ci
63e1051a39Sopenharmony_ci# The year the output file is generated.
64e1051a39Sopenharmony_cimy $YEAR = OpenSSL::copyright::year_of($0);
65e1051a39Sopenharmony_ciprint <<"EOF";
66e1051a39Sopenharmony_ci/*
67e1051a39Sopenharmony_ci * WARNING: do not edit!
68e1051a39Sopenharmony_ci * Generated by crypto/conf/keysets.pl
69e1051a39Sopenharmony_ci *
70e1051a39Sopenharmony_ci * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
71e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
72e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
73e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
74e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
75e1051a39Sopenharmony_ci */
76e1051a39Sopenharmony_ci
77e1051a39Sopenharmony_ci#define CONF_NUMBER       $NUMBER
78e1051a39Sopenharmony_ci#define CONF_UPPER        $UPPER
79e1051a39Sopenharmony_ci#define CONF_LOWER        $LOWER
80e1051a39Sopenharmony_ci#define CONF_UNDER        $UNDER
81e1051a39Sopenharmony_ci#define CONF_PUNCT        $PUNCTUATION
82e1051a39Sopenharmony_ci#define CONF_WS           $WS
83e1051a39Sopenharmony_ci#define CONF_ESC          $ESC
84e1051a39Sopenharmony_ci#define CONF_QUOTE        $QUOTE
85e1051a39Sopenharmony_ci#define CONF_DQUOTE       $DQUOTE
86e1051a39Sopenharmony_ci#define CONF_COMMENT      $COMMENT
87e1051a39Sopenharmony_ci#define CONF_FCOMMENT     $FCOMMENT
88e1051a39Sopenharmony_ci#define CONF_DOLLAR       $DOLLAR
89e1051a39Sopenharmony_ci#define CONF_EOF          $EOF
90e1051a39Sopenharmony_ci#define CONF_ALPHA        (CONF_UPPER|CONF_LOWER)
91e1051a39Sopenharmony_ci#define CONF_ALNUM        (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
92e1051a39Sopenharmony_ci#define CONF_ALNUM_PUNCT  (CONF_ALPHA|CONF_NUMBER|CONF_UNDER|CONF_PUNCT)
93e1051a39Sopenharmony_ci
94e1051a39Sopenharmony_ci
95e1051a39Sopenharmony_ci#define IS_COMMENT(conf,c)     is_keytype(conf, c, CONF_COMMENT)
96e1051a39Sopenharmony_ci#define IS_FCOMMENT(conf,c)    is_keytype(conf, c, CONF_FCOMMENT)
97e1051a39Sopenharmony_ci#define IS_EOF(conf,c)         is_keytype(conf, c, CONF_EOF)
98e1051a39Sopenharmony_ci#define IS_ESC(conf,c)         is_keytype(conf, c, CONF_ESC)
99e1051a39Sopenharmony_ci#define IS_NUMBER(conf,c)      is_keytype(conf, c, CONF_NUMBER)
100e1051a39Sopenharmony_ci#define IS_WS(conf,c)          is_keytype(conf, c, CONF_WS)
101e1051a39Sopenharmony_ci#define IS_ALNUM(conf,c)       is_keytype(conf, c, CONF_ALNUM)
102e1051a39Sopenharmony_ci#define IS_ALNUM_PUNCT(conf,c) is_keytype(conf, c, CONF_ALNUM_PUNCT)
103e1051a39Sopenharmony_ci#define IS_QUOTE(conf,c)       is_keytype(conf, c, CONF_QUOTE)
104e1051a39Sopenharmony_ci#define IS_DQUOTE(conf,c)      is_keytype(conf, c, CONF_DQUOTE)
105e1051a39Sopenharmony_ci#define IS_DOLLAR(conf,c)      is_keytype(conf, c, CONF_DOLLAR)
106e1051a39Sopenharmony_ci
107e1051a39Sopenharmony_ciEOF
108e1051a39Sopenharmony_ci
109e1051a39Sopenharmony_cimy $i;
110e1051a39Sopenharmony_ci
111e1051a39Sopenharmony_ciprint "static const unsigned short CONF_type_default[128] = {";
112e1051a39Sopenharmony_cifor ($i = 0; $i < 128; $i++) {
113e1051a39Sopenharmony_ci    print "\n   " if ($i % 8) == 0;
114e1051a39Sopenharmony_ci    printf " 0x%04X,", $V_def[$i];
115e1051a39Sopenharmony_ci}
116e1051a39Sopenharmony_ciprint "\n};\n\n";
117e1051a39Sopenharmony_ci
118e1051a39Sopenharmony_ciprint "#ifndef OPENSSL_NO_DEPRECATED_3_0\n";
119e1051a39Sopenharmony_ciprint "static const unsigned short CONF_type_win32[128] = {";
120e1051a39Sopenharmony_cifor ($i = 0; $i < 128; $i++) {
121e1051a39Sopenharmony_ci    print "\n   " if ($i % 8) == 0;
122e1051a39Sopenharmony_ci    printf " 0x%04X,", $V_w32[$i];
123e1051a39Sopenharmony_ci}
124e1051a39Sopenharmony_ciprint "\n};\n";
125e1051a39Sopenharmony_ciprint "#endif\n";
126