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() };
32 (my $C_name = $name) =~ s|-|_|g;
33 my $C_bytes_size = 2 + scalar @_;
36 extern const unsigned char der_oid_${C_name}[$C_bytes_size];
41 my ($name, $comment) = @{ shift() };
43 my $oid_size = scalar @oid_nums;
45 croak "Unsupported OID size (>127 bytes)" if $oid_size > 127;
47 (my $C_comment = $comment) =~ s|^| * |msg;
48 $C_comment = "\n/*\n${C_comment}\n */" if $C_comment ne '';
49 (my $C_name = $name) =~ s|-|_|g;
50 my $C_bytes_size = 2 + $oid_size;
51 my $C_bytes = join(', ', map { sprintf("0x%02X", $_) } @oid_nums );
55 #define DER_OID_V_${C_name} DER_P_OBJECT, $oid_size, ${C_bytes}
56 #define DER_OID_SZ_${C_name} ${C_bytes_size}
57 const unsigned char der_oid_${C_name}[DER_OID_SZ_${C_name}] = {
64 my %opts = %{ pop @_ } if ref $_[$#_] eq 'HASH';
66 # To maintain input order
69 foreach my $file (@_) {
70 my $input = File::Spec->catfile($opts{dir}, $file);
71 open my $fh, $input or die "Reading $input: $!\n";
78 # print STDERR "-----BEGIN DEBUG-----\n";
80 # print STDERR "-----END DEBUG-----\n";
82 while ($text =~ m/${OID_def_re}/sg) {
87 # print STDERR "-----BEGIN DEBUG $name-----\n";
88 # print STDERR $value,"\n";
89 # print STDERR "-----END DEBUG $name-----\n";
90 register_oid($name, $value);
91 push @OID_names, [ $name, $comment ];
99 my %opts = %{ $_[$#_] } if ref $_[$#_] eq 'HASH';
100 my @OID_names = _process @_;
103 my %leaves = map { $_ => 1 } registered_oid_leaves;
104 foreach (grep { defined $leaves{$_->[0]} } @OID_names) {
105 my $lines = $opts{filter}->($_, encode_oid($_->[0]));