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