2
0

keysets.pl 4.0 KB

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