File: mkoidtbl.awk

package info (click to toggle)
libksba 1.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 3,996 kB
  • sloc: ansic: 23,298; sh: 12,428; yacc: 859; makefile: 292; sed: 37; awk: 32
file content (60 lines) | stat: -rw-r--r-- 1,848 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# mkoidtbl.awk  - Create OID table from Peter Gutmann's dumpasn1.cfg
# Copyright (C) 2004 g10 Code GmbH
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#

# This file takes a list of OID description in a format like
#
#  # Comment line, the next line identifies a new record
#  OID = 06 05 02 82 06 01 0A
#  Comment = Deutsche Telekom
#  Description = Telesec (0 2 262 1 10)
#
#  And creates a new table in IETF notation with lines like
#  0.2.262.1.10 Telesec Deutsche Telekom
#  comment lines may also occur in the output.
#


BEGIN {
  print "static struct { char *oid, *desc, *comment; } oidtranstbl[] = {"
}

/^[ \t]*#/ { next }
/^OID/     { flush()
             oid = substr($0, index($0, "=") + 2)
             gsub (/[ \t]+/, ".", oid)
}
/^Comment/ { comment = substr($0, index($0, "=") + 2 )
             gsub(/\r/, "", comment)
             gsub (/\\/, "\\\\", comment)
             gsub (/"/, "\\\"", comment)
             gsub (/\(\?\?\?\)/, "(?)", comment)
}
/^Description/ {
  desc = substr($0, index($0, "=") + 2)
  gsub(/\r/, "", desc)
  if (match (desc, /\([0-9 \t]+\)/) > 2) {
    oid = substr(desc, RSTART+1, RLENGTH-2 )
    desc = substr(desc, 1, RSTART-1);
  }
  gsub (/[ \t]+/, ".", oid)
  gsub (/\\/, "\\\\", desc)
  gsub (/"/, "\\\"", desc)
  sub (/[ \t]*$/, "", desc)
}

END { flush();  print "  { NULL, NULL, NULL }\n};"  }

function flush() {
  if(oid && desc)
     printf "  { \"%s\", \"%s\", \"%s\" },\n", oid, desc, comment
  oid = desc = comment = ""
}