diff options
author | Magnus Ahltorp <map@kth.se> | 2015-08-19 09:55:02 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-08-19 09:55:02 +0200 |
commit | a0accd0b207f8b4541d48c75d5b2ccc8b3ceedc4 (patch) | |
tree | d89a20d43ee0b9ec05db14aca4c9935f578ddccc /tools/mergetools.py | |
parent | fd33d62b9e8849a3cca344994183f4fe9fa54d81 (diff) |
Script for converting database to new formatconvertdb
Diffstat (limited to 'tools/mergetools.py')
-rw-r--r-- | tools/mergetools.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/mergetools.py b/tools/mergetools.py index c3e9688..947d7f4 100644 --- a/tools/mergetools.py +++ b/tools/mergetools.py @@ -35,6 +35,11 @@ def tlv_decode(data): rest = data[length:] return (type, value, rest) +def tlv_encode(type, value): + assert(len(type) == 4) + data = struct.pack(">I", len(value) + 8) + type + value + return data + def tlv_decodelist(data): l = [] while len(data): @@ -43,6 +48,12 @@ def tlv_decodelist(data): data = rest return l +def tlv_encodelist(l): + data = "" + for (type, value) in l: + data += tlv_encode(type, value) + return data + def unwrap_entry(entry): ploplevel = tlv_decodelist(entry) assert(len(ploplevel) == 2) @@ -54,6 +65,10 @@ def unwrap_entry(entry): assert(computedchecksum == plopchecksum) return plopdata +def wrap_entry(entry): + return tlv_encodelist([("PLOP", entry), + ("S256", hashlib.sha256(entry).digest())]) + def verify_entry(verifycert, entry, hash): packed = unwrap_entry(entry) unpacked = tlv_decodelist(packed) |