]>
Commit | Line | Data |
---|---|---|
e0a65194 | 1 | #! /usr/bin/env perl |
33388b44 | 2 | # Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. |
e0a65194 | 3 | # |
3f870de7 | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
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 | |
c2bbf9cf | 8 | |
22defb43 RS |
9 | use Getopt::Std; |
10 | ||
11 | our($opt_n); | |
12 | getopts('n'); | |
13 | ||
339638b5 RS |
14 | # The year the output file is generated. |
15 | my $YEAR = [localtime()]->[5] + 1900; | |
97d37b85 | 16 | |
c2bbf9cf RL |
17 | open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]"; |
18 | $max_nid=0; | |
19 | $o=0; | |
20 | while(<NUMIN>) | |
21 | { | |
9ba96fbb | 22 | s|\R$||; |
c2bbf9cf RL |
23 | $o++; |
24 | s/#.*$//; | |
25 | next if /^\s*$/; | |
1d00800e | 26 | $_ = 'X'.$_; |
c2bbf9cf | 27 | ($Cname,$mynum) = split; |
1d00800e | 28 | $Cname =~ s/^X//; |
c2bbf9cf RL |
29 | if (defined($nidn{$mynum})) |
30 | { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; } | |
041e7f2e | 31 | if (defined($nid{$Cname})) |
16fe5f8b | 32 | { die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; } |
c2bbf9cf RL |
33 | $nid{$Cname} = $mynum; |
34 | $nidn{$mynum} = $Cname; | |
35 | $order{$mynum} = $o; | |
36 | $max_nid = $mynum if $mynum > $max_nid; | |
37 | } | |
38 | close NUMIN; | |
39 | ||
40 | open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]"; | |
41 | $Cname=""; | |
42 | $o=0; | |
43 | while (<IN>) | |
44 | { | |
9ba96fbb | 45 | s|\R$||; |
c2bbf9cf RL |
46 | $o++; |
47 | if (/^!module\s+(.*)$/) | |
48 | { | |
49 | $module = $1."-"; | |
50 | $module =~ s/\./_/g; | |
51 | $module =~ s/-/_/g; | |
52 | } | |
53 | if (/^!global$/) | |
54 | { $module = ""; } | |
55 | if (/^!Cname\s+(.*)$/) | |
56 | { $Cname = $1; } | |
57 | if (/^!Alias\s+(.+?)\s+(.*)$/) | |
58 | { | |
59 | $Cname = $module.$1; | |
60 | $myoid = $2; | |
61 | $myoid = &process_oid($myoid); | |
62 | $Cname =~ s/-/_/g; | |
63 | $ordern{$o} = $Cname; | |
64 | $order{$Cname} = $o; | |
65 | $obj{$Cname} = $myoid; | |
66 | $_ = ""; | |
67 | $Cname = ""; | |
68 | } | |
69 | s/!.*$//; | |
70 | s/#.*$//; | |
71 | next if /^\s*$/; | |
72 | ($myoid,$mysn,$myln) = split ':'; | |
73 | $mysn =~ s/^\s*//; | |
74 | $mysn =~ s/\s*$//; | |
75 | $myln =~ s/^\s*//; | |
76 | $myln =~ s/\s*$//; | |
77 | $myoid =~ s/^\s*//; | |
78 | $myoid =~ s/\s*$//; | |
79 | if ($myoid ne "") | |
80 | { | |
81 | $myoid = &process_oid($myoid); | |
82 | } | |
83 | ||
591b7aef | 84 | if ($Cname eq "" && ($myln =~ /^[_A-Za-z][\w.-]*$/ )) |
c2bbf9cf RL |
85 | { |
86 | $Cname = $myln; | |
87 | $Cname =~ s/\./_/g; | |
88 | $Cname =~ s/-/_/g; | |
89 | if ($Cname ne "" && defined($ln{$module.$Cname})) | |
90 | { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; } | |
91 | } | |
92 | if ($Cname eq "") | |
93 | { | |
94 | $Cname = $mysn; | |
95 | $Cname =~ s/-/_/g; | |
96 | if ($Cname ne "" && defined($sn{$module.$Cname})) | |
97 | { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; } | |
98 | } | |
99 | if ($Cname eq "") | |
100 | { | |
101 | $Cname = $myln; | |
102 | $Cname =~ s/-/_/g; | |
103 | $Cname =~ s/\./_/g; | |
104 | $Cname =~ s/ /_/g; | |
105 | if ($Cname ne "" && defined($ln{$module.$Cname})) | |
106 | { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; } | |
107 | } | |
108 | $Cname =~ s/\./_/g; | |
109 | $Cname =~ s/-/_/g; | |
110 | $Cname = $module.$Cname; | |
111 | $ordern{$o} = $Cname; | |
112 | $order{$Cname} = $o; | |
113 | $sn{$Cname} = $mysn; | |
114 | $ln{$Cname} = $myln; | |
115 | $obj{$Cname} = $myoid; | |
116 | if (!defined($nid{$Cname})) | |
117 | { | |
118 | $max_nid++; | |
119 | $nid{$Cname} = $max_nid; | |
120 | $nidn{$max_nid} = $Cname; | |
16fe5f8b | 121 | print STDERR "Added OID $Cname\n"; |
c2bbf9cf RL |
122 | } |
123 | $Cname=""; | |
124 | } | |
125 | close IN; | |
126 | ||
22defb43 RS |
127 | if ( $opt_n ) { |
128 | foreach (sort { $a <=> $b } keys %nidn) | |
129 | { | |
130 | print $nidn{$_},"\t\t",$_,"\n"; | |
131 | } | |
132 | exit; | |
133 | } | |
c2bbf9cf | 134 | |
22defb43 | 135 | print <<"EOF"; |
7ce38623 | 136 | /* |
e0a65194 RS |
137 | * WARNING: do not edit! |
138 | * Generated by crypto/objects/objects.pl | |
7ce38623 | 139 | * |
97d37b85 | 140 | * Copyright 2000-$YEAR The OpenSSL Project Authors. All Rights Reserved. |
3f870de7 | 141 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
142 | * this file except in compliance with the License. You can obtain a copy |
143 | * in the file LICENSE in the source distribution or at | |
144 | * https://www.openssl.org/source/license.html | |
c2bbf9cf RL |
145 | */ |
146 | ||
d59068bd F |
147 | #ifndef OPENSSL_OBJ_MAC_H |
148 | # define OPENSSL_OBJ_MAC_H | |
149 | # pragma once | |
150 | ||
7ce38623 AP |
151 | #define SN_undef "UNDEF" |
152 | #define LN_undef "undefined" | |
153 | #define NID_undef 0 | |
154 | #define OBJ_undef 0L | |
c2bbf9cf RL |
155 | EOF |
156 | ||
7ce38623 AP |
157 | sub expand |
158 | { | |
159 | my $string = shift; | |
160 | ||
161 | 1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; | |
162 | ||
163 | return $string; | |
164 | } | |
165 | ||
c2bbf9cf RL |
166 | foreach (sort { $a <=> $b } keys %ordern) |
167 | { | |
168 | $Cname=$ordern{$_}; | |
22defb43 RS |
169 | print "\n"; |
170 | print expand("#define SN_$Cname\t\t\"$sn{$Cname}\"\n") if $sn{$Cname} ne ""; | |
171 | print expand("#define LN_$Cname\t\t\"$ln{$Cname}\"\n") if $ln{$Cname} ne ""; | |
172 | print expand("#define NID_$Cname\t\t$nid{$Cname}\n") if $nid{$Cname} ne ""; | |
173 | print expand("#define OBJ_$Cname\t\t$obj{$Cname}\n") if $obj{$Cname} ne ""; | |
c2bbf9cf RL |
174 | } |
175 | ||
d59068bd F |
176 | print <<EOF; |
177 | ||
178 | #endif /* OPENSSL_OBJ_MAC_H */ | |
179 | EOF | |
180 | ||
c2bbf9cf RL |
181 | sub process_oid |
182 | { | |
183 | local($oid)=@_; | |
184 | local(@a,$oid_pref); | |
185 | ||
186 | @a = split(/\s+/,$myoid); | |
187 | $pref_oid = ""; | |
27d72600 | 188 | $pref_sep = ""; |
c2bbf9cf RL |
189 | if (!($a[0] =~ /^[0-9]+$/)) |
190 | { | |
191 | $a[0] =~ s/-/_/g; | |
4825092b LJ |
192 | if (!defined($obj{$a[0]})) |
193 | { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; } | |
27d72600 RL |
194 | $pref_oid = "OBJ_" . $a[0]; |
195 | $pref_sep = ","; | |
c2bbf9cf RL |
196 | shift @a; |
197 | } | |
27d72600 RL |
198 | $oids = join('L,',@a) . "L"; |
199 | if ($oids ne "L") | |
200 | { | |
201 | $oids = $pref_oid . $pref_sep . $oids; | |
202 | } | |
203 | else | |
204 | { | |
205 | $oids = $pref_oid; | |
206 | } | |
207 | return($oids); | |
c2bbf9cf | 208 | } |