security/nss/lib/ckfw/builtins/certdata.perl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #!perl -w
michael@0 2 #
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6 use strict;
michael@0 7
michael@0 8 my %constants;
michael@0 9 my $count = 0;
michael@0 10 my $o;
michael@0 11 my @objects = ();
michael@0 12 my @objsize;
michael@0 13
michael@0 14 $constants{CKO_DATA} = "static const CK_OBJECT_CLASS cko_data = CKO_DATA;\n";
michael@0 15 $constants{CK_TRUE} = "static const CK_BBOOL ck_true = CK_TRUE;\n";
michael@0 16 $constants{CK_FALSE} = "static const CK_BBOOL ck_false = CK_FALSE;\n";
michael@0 17
michael@0 18 while(<>) {
michael@0 19 my @fields = ();
michael@0 20 my $size;
michael@0 21
michael@0 22 s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
michael@0 23 next if (/^\s*$/);
michael@0 24
michael@0 25 # This was taken from the perl faq #4.
michael@0 26 my $text = $_;
michael@0 27 push(@fields, $+) while $text =~ m{
michael@0 28 "([^\"\\]*(?:\\.[^\"\\]*)*)"\s? # groups the phrase inside the quotes
michael@0 29 | ([^\s]+)\s?
michael@0 30 | \s
michael@0 31 }gx;
michael@0 32 push(@fields, undef) if substr($text,-1,1) eq '\s';
michael@0 33
michael@0 34 if( $fields[0] =~ /BEGINDATA/ ) {
michael@0 35 next;
michael@0 36 }
michael@0 37
michael@0 38 if( $fields[1] =~ /MULTILINE/ ) {
michael@0 39 $fields[2] = "";
michael@0 40 while(<>) {
michael@0 41 last if /END/;
michael@0 42 chomp;
michael@0 43 $fields[2] .= "\"$_\"\n";
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 if( $fields[1] =~ /UTF8/ ) {
michael@0 48 if( $fields[2] =~ /^"/ ) {
michael@0 49 ;
michael@0 50 } else {
michael@0 51 $fields[2] = "\"" . $fields[2] . "\"";
michael@0 52 }
michael@0 53
michael@0 54 my $scratch = eval($fields[2]);
michael@0 55
michael@0 56 $size = length($scratch) + 1; # null terminate
michael@0 57 }
michael@0 58
michael@0 59 if( $fields[1] =~ /OCTAL/ ) {
michael@0 60 if( $fields[2] =~ /^"/ ) {
michael@0 61 ;
michael@0 62 } else {
michael@0 63 $fields[2] = "\"" . $fields[2] . "\"";
michael@0 64 }
michael@0 65
michael@0 66 my $scratch = $fields[2];
michael@0 67 $size = $scratch =~ tr/\\//;
michael@0 68 # no null termination
michael@0 69 }
michael@0 70
michael@0 71 if( $fields[1] =~ /^CK_/ ) {
michael@0 72 my $lcv = $fields[2];
michael@0 73 $lcv =~ tr/A-Z/a-z/;
michael@0 74 if( !defined($constants{$fields[2]}) ) {
michael@0 75 $constants{$fields[2]} = "static const $fields[1] $lcv = $fields[2];\n";
michael@0 76 }
michael@0 77
michael@0 78 $size = "sizeof($fields[1])";
michael@0 79 $fields[2] = "&$lcv";
michael@0 80 }
michael@0 81
michael@0 82 if( $fields[0] =~ /CKA_CLASS/ ) {
michael@0 83 $count++;
michael@0 84 $objsize[$count] = 0;
michael@0 85 }
michael@0 86
michael@0 87 @{$objects[$count][$objsize[$count]++]} = ( "$fields[0]", $fields[2], "$size" );
michael@0 88
michael@0 89 # print "$fields[0] | $fields[1] | $size | $fields[2]\n";
michael@0 90 }
michael@0 91
michael@0 92 doprint();
michael@0 93
michael@0 94 sub dudump {
michael@0 95 my $i;
michael@0 96 for( $i = 1; $i <= $count; $i++ ) {
michael@0 97 print "\n";
michael@0 98 $o = $objects[$i];
michael@0 99 my @ob = @{$o};
michael@0 100 my $l;
michael@0 101 my $j;
michael@0 102 for( $j = 0; $j < @ob; $j++ ) {
michael@0 103 $l = $ob[$j];
michael@0 104 my @a = @{$l};
michael@0 105 print "$a[0] ! $a[1] ! $a[2]\n";
michael@0 106 }
michael@0 107 }
michael@0 108
michael@0 109 }
michael@0 110
michael@0 111 sub doprint {
michael@0 112 my $i;
michael@0 113
michael@0 114 print <<EOD
michael@0 115 /* THIS IS A GENERATED FILE */
michael@0 116 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 117 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 118 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 119
michael@0 120 #ifndef BUILTINS_H
michael@0 121 #include "builtins.h"
michael@0 122 #endif /* BUILTINS_H */
michael@0 123
michael@0 124 EOD
michael@0 125 ;
michael@0 126
michael@0 127 foreach $b (sort values(%constants)) {
michael@0 128 print $b;
michael@0 129 }
michael@0 130
michael@0 131 for( $i = 1; $i <= $count; $i++ ) {
michael@0 132 print "static const CK_ATTRIBUTE_TYPE nss_builtins_types_$i [] = {\n";
michael@0 133 $o = $objects[$i];
michael@0 134 my @ob = @{$o};
michael@0 135 my $j;
michael@0 136 for( $j = 0; $j < @ob; $j++ ) {
michael@0 137 my $l = $ob[$j];
michael@0 138 my @a = @{$l};
michael@0 139 print " $a[0]";
michael@0 140 if( $j+1 != @ob ) {
michael@0 141 print ", ";
michael@0 142 }
michael@0 143 }
michael@0 144 print "\n};\n";
michael@0 145 }
michael@0 146
michael@0 147 for( $i = 1; $i <= $count; $i++ ) {
michael@0 148 print "static const NSSItem nss_builtins_items_$i [] = {\n";
michael@0 149 $o = $objects[$i];
michael@0 150 my @ob = @{$o};
michael@0 151 my $j;
michael@0 152 for( $j = 0; $j < @ob; $j++ ) {
michael@0 153 my $l = $ob[$j];
michael@0 154 my @a = @{$l};
michael@0 155 print " { (void *)$a[1], (PRUint32)$a[2] }";
michael@0 156 if( $j+1 != @ob ) {
michael@0 157 print ",\n";
michael@0 158 } else {
michael@0 159 print "\n";
michael@0 160 }
michael@0 161 }
michael@0 162 print "};\n";
michael@0 163 }
michael@0 164
michael@0 165 print "\nbuiltinsInternalObject\n";
michael@0 166 print "nss_builtins_data[] = {\n";
michael@0 167
michael@0 168 for( $i = 1; $i <= $count; $i++ ) {
michael@0 169 print " { $objsize[$i], nss_builtins_types_$i, nss_builtins_items_$i, {NULL} }";
michael@0 170 if( $i == $count ) {
michael@0 171 print "\n";
michael@0 172 } else {
michael@0 173 print ",\n";
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 print "};\n";
michael@0 178
michael@0 179 print "const PRUint32\n";
michael@0 180 print "nss_builtins_nObjects = $count;\n";
michael@0 181 }

mercurial