diff options
author | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2007-06-09 12:10:27 +0000 |
---|---|---|
committer | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2007-06-09 12:10:27 +0000 |
commit | fd7bcf04a194efce6301df2f7ca27d18863448d2 (patch) | |
tree | f8dcf6cee602da76d14856151ad7979b6eeafdcb /TLV_utils.py | |
parent | 38bc6d9efc5d5d8eb104737af1cd3e86a6ec696a (diff) |
OID to cleartext
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@237 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'TLV_utils.py')
-rw-r--r-- | TLV_utils.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/TLV_utils.py b/TLV_utils.py index 38128db..48263b7 100644 --- a/TLV_utils.py +++ b/TLV_utils.py @@ -145,9 +145,34 @@ def parse_oid(value): return tuple(result) +oidCache = {} +def loadOids(filename="oids.txt"): + try: + fp = file(filename, "r") + except (SystemExit,KeyboardInterrupt): + raise + except: + pass + else: + try: + lines = fp.readlines() + finally: + fp.close() + for line in lines: + if line.strip() == "" or line[0] == "#": + continue + parts = line.strip().split(None,2) + if len(parts) < 3: + parts.append(parts[1]) + oidCache[parts[0]] = tuple(parts[1:]) + def decode_oid(value): oid = parse_oid(value) - return " " + ".".join([str(a) for a in oid]) + str_rep = ".".join([str(a) for a in oid]) + + if len(oidCache) == 0: + loadOids() + return " %s (%s)" % (str_rep, oidCache.get(str_rep, ("No description available",))[0]) _gtimere = sre.compile(r'(\d{4})(\d\d)(\d\d)(\d\d)(?:(\d\d)(\d\d(?:[.,]\d+)?)?)?(|Z|(?:[+-]\d\d(?:\d\d)?))$') def decode_generalized_time(value): @@ -484,3 +509,5 @@ if __name__ == "__main__": c = pack(b, recalculate_length = True) print utils.hexdump(a) print utils.hexdump(c) + + loadOids() |