#!perl # # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # 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 the Initial Developer are Copyright (C) 1994-2000 # the Initial Developer. All Rights Reserved. # # Contributor(s): # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** $cvs_id = '@(#) $RCSfile: oidgen.perl,v $ $Revision: 1.5 $ $Date: 2005/02/02 22:28:24 $'; $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; }