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