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