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