#!/usr/pkg/bin/python from string import * from os import listdir db = open("oids.db","r") oids = [] urls = {} descriptions = {} shortnames = {} shortnames["1"] = "iso" shortnames["1.2"] = "member-body" shortnames["1.2.826"] = "gb" shortnames["1.2.826.0"] = "national" shortnames["1.2.826.0.1"] = "eng-ltd" while 1: line = db.readline() if not line: break (oid,shortname,url,description) = split(line,None,3) shortnames[oid] = shortname descriptions[oid] = strip(description) urls[oid] = url oids.append(oid) oids.sort() db.close() def oid_asn1_format(oid): parts = split(oid,".") curoid = "" string = "{" while len(parts) > 0: item = parts.pop(0) if curoid != "": curoid = curoid + "." curoid = curoid + item if shortnames.has_key(curoid): string = string + " %s(%s)" % (shortnames[curoid],item) else: string = string + " %s" % item return string + " }" # Generate index.html html = open("index.html","w") html.write("Warhead.org.uk OID registry\n") for oid in oids: url = urls[oid] description = descriptions[oid] spaces = " " * (len(split(oid,"."))-5) * 8 if url == "-": html.write("%s%s
%s %s
\n" % (spaces,oid_asn1_format(oid),spaces,description)) else: html.write("%s%s
%s %s
\n" % (spaces,url,oid_asn1_format(oid),spaces,description)) html.write("\n") html.close() # Generate assignments.asn1 asn = open("assignments.asn1","w") asn.write("assignments " + oid_asn1_format("1.2.826.0.1.4062548.0.0") + " DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n\n") for oid in oids: url = urls[oid] description = descriptions[oid] shortname = shortnames[oid] asn.write("-- %s --\nid-%s OBJECT IDENTIFIER ::= \n%s\n\n" % (description,shortname,oid_asn1_format(oid))) asn.write("END") asn.close()