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

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

mercurial