From effcdb703b617bdfb1396c9d5db3efc6f00fffbe Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Sat, 22 Jun 2024 12:44:42 +0200 Subject: [PATCH] IETF test vectors parsing script --- data/ietf-vector-schema.py | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 data/ietf-vector-schema.py diff --git a/data/ietf-vector-schema.py b/data/ietf-vector-schema.py new file mode 100755 index 0000000..1cb956a --- /dev/null +++ b/data/ietf-vector-schema.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import json +import sys + + +def print_entry(entry, key, max_length=64, continuation_prefix=".."): + value = entry.get(key, "-") + text = value if value else "-" + first_line = True + + while len(text) > max_length: + split_point = max_length + print(text[:split_point]) + text = continuation_prefix + text[split_point:] + if first_line is True: + max_length += len(continuation_prefix) + first_line = False + print("{},".format(text)) + + +def main(file_name): + with open(file_name, 'r') as file: + data = json.load(file) + + schema = [ + ("sk", 64), + ("pk", 66), + ("alpha", 64), + ("ad", 64), + ("h", 66), + ("gamma", 66), + ("beta", 64), + ("proof_c", 64), + ("proof_s", 64) + ] + print("----- SCHEMA -----") + for (key, line_max) in schema: + print(key) + print("------------------\n") + + for entry in data: + comment = entry.get("comment", "???") + print("### {}".format(comment)) + print("\n```") + for (key, line_max) in schema: + print_entry(entry, key, line_max) + print("```\n") + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + file_name = sys.argv[1] + main(file_name)