Skip to content

Commit

Permalink
IETF test vectors parsing script
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jun 22, 2024
1 parent 9721a86 commit effcdb7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions data/ietf-vector-schema.py
Original file line number Diff line number Diff line change
@@ -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: {} <vectors.json>".format(sys.argv[0]))
sys.exit(1)

file_name = sys.argv[1]
main(file_name)

0 comments on commit effcdb7

Please sign in to comment.