diff options
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) |