Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

objects.pl 7.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #!/usr/bin/env perl
  2. if (scalar @ARGV != 3)
  3. {
  4. print "Usage: perl objects.pl objects.txt obj_mac.num ../../include/openssl/nid.h\n";
  5. exit 1;
  6. }
  7. open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
  8. $max_nid=0;
  9. $o=0;
  10. while(<NUMIN>)
  11. {
  12. chop;
  13. $o++;
  14. s/#.*$//;
  15. next if /^\s*$/;
  16. $_ = 'X'.$_;
  17. ($Cname,$mynum) = split;
  18. $Cname =~ s/^X//;
  19. if (defined($nidn{$mynum}))
  20. { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
  21. if (defined($nid{$Cname}))
  22. { die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; }
  23. $nid{$Cname} = $mynum;
  24. $nidn{$mynum} = $Cname;
  25. $order{$mynum} = $o;
  26. $max_nid = $mynum if $mynum > $max_nid;
  27. }
  28. close NUMIN;
  29. open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
  30. $Cname="";
  31. $o=0;
  32. while (<IN>)
  33. {
  34. chop;
  35. $o++;
  36. if (/^!module\s+(.*)$/)
  37. {
  38. $module = $1."-";
  39. $module =~ s/\./_/g;
  40. $module =~ s/-/_/g;
  41. }
  42. if (/^!global$/)
  43. { $module = ""; }
  44. if (/^!Cname\s+(.*)$/)
  45. { $Cname = $1; }
  46. if (/^!Alias\s+(.+?)\s+(.*)$/)
  47. {
  48. $Cname = $module.$1;
  49. $myoid = $2;
  50. $myoid = &process_oid($myoid);
  51. $Cname =~ s/-/_/g;
  52. $ordern{$o} = $Cname;
  53. $order{$Cname} = $o;
  54. $obj{$Cname} = $myoid;
  55. $_ = "";
  56. $Cname = "";
  57. }
  58. s/!.*$//;
  59. s/#.*$//;
  60. next if /^\s*$/;
  61. ($myoid,$mysn,$myln) = split ':';
  62. $mysn =~ s/^\s*//;
  63. $mysn =~ s/\s*$//;
  64. $myln =~ s/^\s*//;
  65. $myln =~ s/\s*$//;
  66. $myoid =~ s/^\s*//;
  67. $myoid =~ s/\s*$//;
  68. if ($myoid ne "")
  69. {
  70. $myoid = &process_oid($myoid);
  71. }
  72. if ($Cname eq "" && !($myln =~ / /))
  73. {
  74. $Cname = $myln;
  75. $Cname =~ s/\./_/g;
  76. $Cname =~ s/-/_/g;
  77. if ($Cname ne "" && defined($ln{$module.$Cname}))
  78. { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  79. }
  80. if ($Cname eq "")
  81. {
  82. $Cname = $mysn;
  83. $Cname =~ s/-/_/g;
  84. if ($Cname ne "" && defined($sn{$module.$Cname}))
  85. { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  86. }
  87. if ($Cname eq "")
  88. {
  89. $Cname = $myln;
  90. $Cname =~ s/-/_/g;
  91. $Cname =~ s/\./_/g;
  92. $Cname =~ s/ /_/g;
  93. if ($Cname ne "" && defined($ln{$module.$Cname}))
  94. { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
  95. }
  96. $Cname =~ s/\./_/g;
  97. $Cname =~ s/-/_/g;
  98. $Cname = $module.$Cname;
  99. $ordern{$o} = $Cname;
  100. $order{$Cname} = $o;
  101. $sn{$Cname} = $mysn;
  102. $ln{$Cname} = $myln;
  103. $obj{$Cname} = $myoid;
  104. if (!defined($nid{$Cname}))
  105. {
  106. $max_nid++;
  107. $nid{$Cname} = $max_nid;
  108. $nidn{$max_nid} = $Cname;
  109. print STDERR "Added OID $Cname\n";
  110. }
  111. $Cname="";
  112. }
  113. close IN;
  114. open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
  115. foreach (sort { $a <=> $b } keys %nidn)
  116. {
  117. print NUMOUT $nidn{$_},"\t\t",$_,"\n";
  118. }
  119. close NUMOUT;
  120. open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
  121. print OUT <<'EOF';
  122. /* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
  123. * following command:
  124. * perl objects.pl objects.txt obj_mac.num ../../include/openssl/nid.h */
  125. /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  126. * All rights reserved.
  127. *
  128. * This package is an SSL implementation written
  129. * by Eric Young (eay@cryptsoft.com).
  130. * The implementation was written so as to conform with Netscapes SSL.
  131. *
  132. * This library is free for commercial and non-commercial use as long as
  133. * the following conditions are aheared to. The following conditions
  134. * apply to all code found in this distribution, be it the RC4, RSA,
  135. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  136. * included with this distribution is covered by the same copyright terms
  137. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  138. *
  139. * Copyright remains Eric Young's, and as such any Copyright notices in
  140. * the code are not to be removed.
  141. * If this package is used in a product, Eric Young should be given attribution
  142. * as the author of the parts of the library used.
  143. * This can be in the form of a textual message at program startup or
  144. * in documentation (online or textual) provided with the package.
  145. *
  146. * Redistribution and use in source and binary forms, with or without
  147. * modification, are permitted provided that the following conditions
  148. * are met:
  149. * 1. Redistributions of source code must retain the copyright
  150. * notice, this list of conditions and the following disclaimer.
  151. * 2. Redistributions in binary form must reproduce the above copyright
  152. * notice, this list of conditions and the following disclaimer in the
  153. * documentation and/or other materials provided with the distribution.
  154. * 3. All advertising materials mentioning features or use of this software
  155. * must display the following acknowledgement:
  156. * "This product includes cryptographic software written by
  157. * Eric Young (eay@cryptsoft.com)"
  158. * The word 'cryptographic' can be left out if the rouines from the library
  159. * being used are not cryptographic related :-).
  160. * 4. If you include any Windows specific code (or a derivative thereof) from
  161. * the apps directory (application code) you must include an acknowledgement:
  162. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  163. *
  164. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  165. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  166. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  167. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  168. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  169. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  170. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  171. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  172. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  173. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  174. * SUCH DAMAGE.
  175. *
  176. * The licence and distribution terms for any publically available version or
  177. * derivative of this code cannot be changed. i.e. this code cannot simply be
  178. * copied and put under another distribution licence
  179. * [including the GNU Public Licence.]
  180. */
  181. #ifndef OPENSSL_HEADER_NID_H
  182. #define OPENSSL_HEADER_NID_H
  183. /* The nid library provides numbered values for ASN.1 object identifiers and
  184. * other symbols. These values are used by other libraries to identify
  185. * cryptographic primitives.
  186. *
  187. * A separate objects library, obj.h, provides functions for converting between
  188. * nids and object identifiers. However it depends on large internal tables with
  189. * the encodings of every nid defind. Consumers concerned with binary size
  190. * should instead embed the encodings of the few consumed OIDs and compare
  191. * against those.
  192. *
  193. * These values should not be used outside of a single process; they are not
  194. * stable identifiers. */
  195. #define SN_undef "UNDEF"
  196. #define LN_undef "undefined"
  197. #define NID_undef 0
  198. #define OBJ_undef 0L
  199. EOF
  200. foreach (sort { $a <=> $b } keys %ordern)
  201. {
  202. $Cname=$ordern{$_};
  203. print OUT "#define SN_",$Cname," \"",$sn{$Cname},"\"\n" if $sn{$Cname} ne "";
  204. print OUT "#define LN_",$Cname," \"",$ln{$Cname},"\"\n" if $ln{$Cname} ne "";
  205. print OUT "#define NID_",$Cname," ",$nid{$Cname},"\n" if $nid{$Cname} ne "";
  206. print OUT "#define OBJ_",$Cname," ",$obj{$Cname},"\n" if $obj{$Cname} ne "";
  207. print OUT "\n";
  208. }
  209. print OUT "\n#endif /* OPENSSL_HEADER_NID_H */\n";
  210. close OUT;
  211. sub process_oid
  212. {
  213. local($oid)=@_;
  214. local(@a,$oid_pref);
  215. @a = split(/\s+/,$myoid);
  216. $pref_oid = "";
  217. $pref_sep = "";
  218. if (!($a[0] =~ /^[0-9]+$/))
  219. {
  220. $a[0] =~ s/-/_/g;
  221. if (!defined($obj{$a[0]}))
  222. { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
  223. $pref_oid = "OBJ_" . $a[0];
  224. $pref_sep = ",";
  225. shift @a;
  226. }
  227. $oids = join('L,',@a) . "L";
  228. if ($oids ne "L")
  229. {
  230. $oids = $pref_oid . $pref_sep . $oids;
  231. }
  232. else
  233. {
  234. $oids = $pref_oid;
  235. }
  236. return($oids);
  237. }