keysets.pl 4.0 KB

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