~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/pki1/oidgen.perl

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
 
3
# The contents of this file are subject to the Mozilla Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/MPL/
 
7
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
 
13
# The Original Code is the Netscape security libraries.
 
14
 
15
# The Initial Developer of the Original Code is Netscape
 
16
# Communications Corporation.  Portions created by Netscape are 
 
17
# Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
18
# Rights Reserved.
 
19
 
20
# Contributor(s):
 
21
 
22
# Alternatively, the contents of this file may be used under the
 
23
# terms of the GNU General Public License Version 2 or later (the
 
24
# "GPL"), in which case the provisions of the GPL are applicable 
 
25
# instead of those above.  If you wish to allow use of your 
 
26
# version of this file only under the terms of the GPL and not to
 
27
# allow others to use your version of this file under the MPL,
 
28
# indicate your decision by deleting the provisions above and
 
29
# replace them with the notice and other provisions required by
 
30
# the GPL.  If you do not delete the provisions above, a recipient
 
31
# may use your version of this file under either the MPL or the
 
32
# GPL.
 
33
#
 
34
$cvs_id = '@(#) $RCSfile: oidgen.perl,v $ $Revision: 1.2 $ $Date: 2001/11/08 00:15:25 $ $Name: FIREFOX_1_0_RELEASE $';
 
35
$cfile = shift;
 
36
$hfile = shift;
 
37
$count = -1;
 
38
while(<>) {
 
39
  s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
 
40
  next if (/^\s*$/);
 
41
 
 
42
  /^([\S]+)\s+([^"][\S]*|"[^"]*")/;
 
43
  $name = $1;
 
44
  $value = $2;
 
45
  # This is certainly not the best way to dequote the data.
 
46
  $value =~ s/"//g;
 
47
 
 
48
  if( $name =~ "OID" ) {
 
49
    $count++;
 
50
    $x[$count]{$name} = $value;
 
51
    $enc = encodeoid($value);
 
52
    $x[$count]{" encoding"} = escapeoid($enc);
 
53
    $x[$count]{" encoding length"} = length($enc);
 
54
  } else {
 
55
    if( $count < 0 ) {
 
56
      $g{$name} = $value;
 
57
    } else {
 
58
      $x[$count]{$name} = $value;
 
59
    }
 
60
  }
 
61
}
 
62
 
 
63
# dodump();
 
64
 
 
65
doprint($cfile,$hfile);
 
66
 
 
67
sub dodump {
 
68
for( $i = 0; $i <= $count; $i++ ) {
 
69
  print "number $i:\n";
 
70
  %y = %{$x[$i]};
 
71
  while(($n,$v) = each(%y)) {
 
72
    print "\t$n ==> $v\n";
 
73
  }
 
74
}
 
75
}
 
76
 
 
77
sub doprint {
 
78
open(CFILE, "> $cfile") || die "Can't open $cfile: $!"; 
 
79
open(HFILE, "> $hfile") || die "Can't open $hfile: $!";
 
80
 
 
81
print CFILE <<EOD
 
82
/* THIS IS A GENERATED FILE */
 
83
/* 
 
84
 * The contents of this file are subject to the Mozilla Public
 
85
 * License Version 1.1 (the "License"); you may not use this file
 
86
 * except in compliance with the License. You may obtain a copy of
 
87
 * the License at http://www.mozilla.org/MPL/
 
88
 * 
 
89
 * Software distributed under the License is distributed on an "AS
 
90
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
91
 * implied. See the License for the specific language governing
 
92
 * rights and limitations under the License.
 
93
 * 
 
94
 * The Original Code is the Netscape security libraries.
 
95
 * 
 
96
 * The Initial Developer of the Original Code is Netscape
 
97
 * Communications Corporation.  Portions created by Netscape are 
 
98
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
99
 * Rights Reserved.
 
100
 * 
 
101
 * Contributor(s):
 
102
 * 
 
103
 * Alternatively, the contents of this file may be used under the
 
104
 * terms of the GNU General Public License Version 2 or later (the
 
105
 * "GPL"), in which case the provisions of the GPL are applicable 
 
106
 * instead of those above.  If you wish to allow use of your 
 
107
 * version of this file only under the terms of the GPL and not to
 
108
 * allow others to use your version of this file under the MPL,
 
109
 * indicate your decision by deleting the provisions above and
 
110
 * replace them with the notice and other provisions required by
 
111
 * the GPL.  If you do not delete the provisions above, a recipient
 
112
 * may use your version of this file under either the MPL or the
 
113
 * GPL.
 
114
 */
 
115
#ifdef DEBUG
 
116
static const char CVS_ID[] = "$g{CVS_ID} ; $cvs_id";
 
117
#endif /* DEBUG */
 
118
 
 
119
#ifndef PKI1T_H
 
120
#include "pki1t.h"
 
121
#endif /* PKI1T_H */
 
122
 
 
123
const NSSOID nss_builtin_oids[] = {
 
124
EOD
 
125
    ;
 
126
 
 
127
for( $i = 0; $i <= $count; $i++ ) {
 
128
  %y = %{$x[$i]};
 
129
  print CFILE "  {\n";
 
130
  print CFILE "#ifdef DEBUG\n";
 
131
  print CFILE "    \"$y{TAG}\",\n";
 
132
  print CFILE "    \"$y{EXPL}\",\n";
 
133
  print CFILE "#endif /* DEBUG */\n";
 
134
  print CFILE "    { \"", $y{" encoding"};
 
135
  print CFILE "\", ", $y{" encoding length"}, " }\n";
 
136
 
 
137
  if( $i == $count ) {
 
138
    print CFILE "  }\n";
 
139
  } else {
 
140
    print CFILE "  },\n";
 
141
  }
 
142
}
 
143
 
 
144
print CFILE "};\n\n";
 
145
 
 
146
print CFILE "const PRUint32 nss_builtin_oid_count = ", ($count+1), ";\n\n";
 
147
 
 
148
for( $i = 0; $i <= $count; $i++ ) {
 
149
  %y = %{$x[$i]};
 
150
  if( defined($y{NAME}) ) {
 
151
    print CFILE "const NSSOID *$y{NAME} = (NSSOID *)&nss_builtin_oids[$i];\n";
 
152
  }
 
153
}
 
154
 
 
155
print CFILE "\n";
 
156
 
 
157
$attrcount = -1;
 
158
for( $i = 0; $i <= $count; $i++ ) {
 
159
  %y = %{$x[$i]};
 
160
  if( defined($y{ATTR}) ) {
 
161
    if( defined($y{NAME}) ) {
 
162
      $attrcount++;
 
163
      $attr[$attrcount]{ATTR} = $y{ATTR};
 
164
      $attr[$attrcount]{NAME} = $y{NAME};
 
165
    } else {
 
166
      warn "Attribute $y{ATTR} has no name, and will be omitted!";
 
167
    }
 
168
  }
 
169
}
 
170
 
 
171
print CFILE "const nssAttributeTypeAliasTable nss_attribute_type_aliases[] = {\n";
 
172
 
 
173
for( $i = 0; $i <= $attrcount; $i++ ) {
 
174
  %y = %{$attr[$i]};
 
175
  print CFILE "  {\n";
 
176
  print CFILE "    \"$y{ATTR}\",\n";
 
177
  print CFILE "    &$y{NAME}\n";
 
178
 
 
179
  if( $i == $attrcount ) {
 
180
    print CFILE "  }\n";
 
181
  } else {
 
182
    print CFILE "  },\n";
 
183
  }
 
184
}
 
185
 
 
186
print CFILE "};\n\n";
 
187
 
 
188
print CFILE "const PRUint32 nss_attribute_type_alias_count = ", ($attrcount+1), ";\n\n";
 
189
 
 
190
print HFILE <<EOD
 
191
/* THIS IS A GENERATED FILE */
 
192
/* 
 
193
 * The contents of this file are subject to the Mozilla Public
 
194
 * License Version 1.1 (the "License"); you may not use this file
 
195
 * except in compliance with the License. You may obtain a copy of
 
196
 * the License at http://www.mozilla.org/MPL/
 
197
 * 
 
198
 * Software distributed under the License is distributed on an "AS
 
199
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
200
 * implied. See the License for the specific language governing
 
201
 * rights and limitations under the License.
 
202
 * 
 
203
 * The Original Code is the Netscape security libraries.
 
204
 * 
 
205
 * The Initial Developer of the Original Code is Netscape
 
206
 * Communications Corporation.  Portions created by Netscape are 
 
207
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
208
 * Rights Reserved.
 
209
 * 
 
210
 * Contributor(s):
 
211
 * 
 
212
 * Alternatively, the contents of this file may be used under the
 
213
 * terms of the GNU General Public License Version 2 or later (the
 
214
 * "GPL"), in which case the provisions of the GPL are applicable 
 
215
 * instead of those above.  If you wish to allow use of your 
 
216
 * version of this file only under the terms of the GPL and not to
 
217
 * allow others to use your version of this file under the MPL,
 
218
 * indicate your decision by deleting the provisions above and
 
219
 * replace them with the notice and other provisions required by
 
220
 * the GPL.  If you do not delete the provisions above, a recipient
 
221
 * may use your version of this file under either the MPL or the
 
222
 * GPL.
 
223
 */
 
224
 
 
225
#ifndef OIDDATA_H
 
226
#define OIDDATA_H
 
227
 
 
228
#ifdef DEBUG
 
229
static const char OIDDATA_CVS_ID[] = "$g{CVS_ID} ; $cvs_id";
 
230
#endif /* DEBUG */
 
231
 
 
232
#ifndef NSSPKI1T_H
 
233
#include "nsspki1t.h"
 
234
#endif /* NSSPKI1T_H */
 
235
 
 
236
extern const NSSOID nss_builtin_oids[];
 
237
extern const PRUint32 nss_builtin_oid_count;
 
238
 
 
239
/*extern const nssAttributeTypeAliasTable nss_attribute_type_aliases[];*/
 
240
/*extern const PRUint32 nss_attribute_type_alias_count;*/
 
241
 
 
242
EOD
 
243
    ;
 
244
 
 
245
for( $i = 0; $i <= $count; $i++ ) {
 
246
  %y = %{$x[$i]};
 
247
  if( defined($y{NAME}) ) {
 
248
    print HFILE "extern const NSSOID *$y{NAME};\n";
 
249
  }
 
250
}
 
251
 
 
252
print HFILE <<EOD
 
253
 
 
254
#endif /* OIDDATA_H */
 
255
EOD
 
256
    ;
 
257
 
 
258
close CFILE;
 
259
close HFILE;
 
260
}
 
261
 
 
262
sub encodenum {
 
263
    my $v = $_[0];
 
264
    my @d;
 
265
    my $i;
 
266
    my $rv = "";
 
267
 
 
268
    while( $v > 128 ) {
 
269
        push @d, ($v % 128);
 
270
        $v /= 128;
 
271
    };
 
272
    push @d, ($v%128);
 
273
 
 
274
    for( $i = @d-1; $i > 0; $i-- ) {
 
275
        $rv = $rv . chr(128 + $d[$i]);
 
276
    }
 
277
 
 
278
    $rv = $rv . chr($d[0]);
 
279
 
 
280
    return $rv;
 
281
}
 
282
 
 
283
sub encodeoid {
 
284
    my @o = split(/\./, $_[0]);
 
285
    my $rv = "";
 
286
    my $i;
 
287
 
 
288
    if( @o < 2 ) {
 
289
        # NSS's special "illegal" encoding
 
290
        return chr(128) . encodenum($o[0]);
 
291
    }
 
292
 
 
293
    $rv = encodenum($o[0] * 40 + $o[1]);
 
294
    shift @o; shift @o;
 
295
 
 
296
    foreach $i (@o) {
 
297
        $rv = $rv . encodenum($i);
 
298
    }
 
299
 
 
300
    return $rv;
 
301
}
 
302
 
 
303
sub escapeoid {
 
304
  my @v = unpack("C*", $_[0]);
 
305
  my $a;
 
306
  my $rv = "";
 
307
 
 
308
  foreach $a (@v) {
 
309
    $rv = $rv . sprintf("\\x%02x", $a);
 
310
  }
 
311
 
 
312
  return $rv;
 
313
}