2 # Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
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
18 my $OID_name_re = qr/([a-z](?:[-_A-Za-z0-9]*[A-Za-z0-9])?)/;
19 my $OID_value_re = qr/(\{.*?\})/s;
21 ${OID_name_re} \s+ OBJECT \s+ IDENTIFIER \s*
29 my ($name, $comment) = @{ shift() };
31 my $oid_size = scalar @oid_nums;
33 (my $C_comment = $comment) =~ s|^| * |msg;
34 $C_comment = "\n/*\n${C_comment}\n */" if $C_comment ne '';
35 (my $C_name = $name) =~ s|-|_|g;
36 my $C_bytes_size = 2 + scalar @_;
37 my $C_bytes = join(', ', map { sprintf("0x%02X", $_) } @oid_nums );
41 #define DER_OID_V_${C_name} DER_P_OBJECT, $oid_size, ${C_bytes}
42 #define DER_OID_SZ_${C_name} ${C_bytes_size}
43 extern const unsigned char der_oid_${C_name}[DER_OID_SZ_${C_name}];
48 my ($name, $comment) = @{ shift() };
50 my $oid_size = scalar @oid_nums;
52 croak "Unsupported OID size (>127 bytes)" if $oid_size > 127;
54 (my $C_comment = $comment) =~ s|^| * |msg;
55 $C_comment = "\n/*\n${C_comment}\n */" if $C_comment ne '';
56 (my $C_name = $name) =~ s|-|_|g;
57 my $C_bytes_size = 2 + $oid_size;
61 const unsigned char der_oid_${C_name}[DER_OID_SZ_${C_name}] = {
68 my %opts = %{ pop @_ } if ref $_[$#_] eq 'HASH';
70 # To maintain input order
73 foreach my $file (@_) {
74 my $input = File::Spec->catfile($opts{dir}, $file);
75 open my $fh, $input or die "Reading $input: $!\n";
82 # print STDERR "-----BEGIN DEBUG-----\n";
84 # print STDERR "-----END DEBUG-----\n";
86 while ($text =~ m/${OID_def_re}/sg) {
91 # print STDERR "-----BEGIN DEBUG $name-----\n";
92 # print STDERR $value,"\n";
93 # print STDERR "-----END DEBUG $name-----\n";
94 register_oid($name, $value);
95 push @OID_names, [ $name, $comment ];
103 my %opts = %{ $_[$#_] } if ref $_[$#_] eq 'HASH';
104 my @OID_names = _process @_;
107 my %leaves = map { $_ => 1 } registered_oid_leaves;
108 foreach (grep { defined $leaves{$_->[0]} } @OID_names) {
109 my $lines = $opts{filter}->($_, encode_oid($_->[0]));