Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/crypto/objects/objxref.pl

raw
1 #! /usr/bin/env perl
2 # Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the Apache License 2.0 (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 use strict;
10 use FindBin;
11 use lib "$FindBin::Bin/../../util/perl";
12 use OpenSSL::copyright;
13
14 my %xref_tbl;
15 my %oid_tbl;
16
17 my ($mac_file, $xref_file) = @ARGV;
18
19 # The year the output file is generated.
20 my $YEAR = OpenSSL::copyright::latest(($0, $mac_file, $xref_file));
21
22 open(IN, $mac_file) || die "Can't open $mac_file, $!\n";
23
24 # Read in OID nid values for a lookup table.
25
26 while (<IN>)
27 {
28 s|\R$||; # Better chomp
29 my ($name, $num) = /^(\S+)\s+(\S+)$/;
30 $oid_tbl{$name} = $num;
31 }
32 close IN;
33
34 open(IN, $xref_file) || die "Can't open $xref_file, $!\n";
35
36 my $ln = 1;
37
38 while (<IN>)
39 {
40 s|\R$||; # Better chomp
41 s/#.*$//;
42 next if (/^\S*$/);
43 my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
44 check_oid($xr);
45 check_oid($p1);
46 check_oid($p2);
47 $xref_tbl{$xr} = [$p1, $p2, $ln];
48 }
49
50 my @xrkeys = keys %xref_tbl;
51
52 my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
53
54 my $i;
55 for($i = 0; $i <= $#srt1; $i++)
56 {
57 $xref_tbl{$srt1[$i]}[2] = $i;
58 }
59
60 my @srt2 = sort
61 {
62 my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
63 my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
64 return $ap1 - $bp1 if ($ap1 != $bp1);
65 my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
66 my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
67
68 return $ap2 - $bp2;
69 } @xrkeys;
70
71 my $pname = $0;
72 $pname =~ s|.*/||;
73
74 print <<EOF;
75 /*
76 * WARNING: do not edit!
77 * Generated by $pname
78 *
79 * Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
80 *
81 * Licensed under the Apache License 2.0 (the "License"). You may not use
82 * this file except in compliance with the License. You can obtain a copy
83 * in the file LICENSE in the source distribution or at
84 * https://www.openssl.org/source/license.html
85 */
86
87
88 typedef struct {
89 int sign_id;
90 int hash_id;
91 int pkey_id;
92 } nid_triple;
93
94 DEFINE_STACK_OF(nid_triple)
95
96 static const nid_triple sigoid_srt[] = {
97 EOF
98
99 foreach (@srt1)
100 {
101 my $xr = $_;
102 my ($p1, $p2) = @{$xref_tbl{$_}};
103 my $o1 = " {NID_$xr, NID_$p1,";
104 my $o2 = "NID_$p2},";
105 if (length("$o1 $o2") < 78)
106 {
107 print "$o1 $o2\n";
108 }
109 else
110 {
111 print "$o1\n $o2\n";
112 }
113 }
114
115 print "};";
116 print <<EOF;
117
118
119 static const nid_triple *const sigoid_srt_xref[] = {
120 EOF
121
122 foreach (@srt2)
123 {
124 my ($p1, $p2, $x) = @{$xref_tbl{$_}};
125 # If digest or signature algorithm is "undef" then the algorithm
126 # needs special handling and is excluded from the cross reference table.
127 next if $p1 eq "undef" || $p2 eq "undef";
128 print " \&sigoid_srt\[$x\],\n";
129 }
130
131 print "};\n";
132
133 sub check_oid
134 {
135 my ($chk) = @_;
136 if (!exists $oid_tbl{$chk})
137 {
138 die "Can't find \"$chk\"\n";
139 }
140 }