#!perl # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Netscape security libraries. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are # Copyright (C) 1994-2000 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): # # Alternatively, the contents of this file may be used under the # terms of the GNU General Public License Version 2 or later (the # "GPL"), in which case the provisions of the GPL are applicable # instead of those above. If you wish to allow use of your # version of this file only under the terms of the GPL and not to # allow others to use your version of this file under the MPL, # indicate your decision by deleting the provisions above and # replace them with the notice and other provisions required by # the GPL. If you do not delete the provisions above, a recipient # may use your version of this file under either the MPL or the # GPL. # $cvs_id = '@(#) $RCSfile$ $Revision$ $Date$ $Name$'; $cfile = shift; $hfile = shift; $count = -1; while(<>) { s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/; next if (/^\s*$/); /^([\S]+)\s+([^"][\S]*|"[^"]*")/; $name = $1; $value = $2; # This is certainly not the best way to dequote the data. $value =~ s/"//g; if( $name =~ "OID" ) { $count++; $x[$count]{$name} = $value; $enc = encodeoid($value); $x[$count]{" encoding"} = escapeoid($enc); $x[$count]{" encoding length"} = length($enc); } else { if( $count < 0 ) { $g{$name} = $value; } else { $x[$count]{$name} = $value; } } } # dodump(); doprint($cfile,$hfile); sub dodump { for( $i = 0; $i <= $count; $i++ ) { print "number $i:\n"; %y = %{$x[$i]}; while(($n,$v) = each(%y)) { print "\t$n ==> $v\n"; } } } sub doprint { open(CFILE, "> $cfile") || die "Can't open $cfile: $!"; open(HFILE, "> $hfile") || die "Can't open $hfile: $!"; print CFILE < 128 ) { push @d, ($v % 128); $v /= 128; }; push @d, ($v%128); for( $i = @d-1; $i > 0; $i-- ) { $rv = $rv . chr(128 + $d[$i]); } $rv = $rv . chr($d[0]); return $rv; } sub encodeoid { my @o = split(/\./, $_[0]); my $rv = ""; my $i; if( @o < 2 ) { # NSS's special "illegal" encoding return chr(128) . encodenum($o[0]); } $rv = encodenum($o[0] * 40 + $o[1]); shift @o; shift @o; foreach $i (@o) { $rv = $rv . encodenum($i); } return $rv; } sub escapeoid { my @v = unpack("C*", $_[0]); my $a; my $rv = ""; foreach $a (@v) { $rv = $rv . sprintf("\\x%02x", $a); } return $rv; }