Skip to content

Commit

Permalink
tests: lint wycheproof's python script
Browse files Browse the repository at this point in the history
This PR lints tests_wycheproof_generate.py according to bitcoin's
python linting scripts. This is a follow-up to PR #1245.

Co-authored-by: Sean Andersen <[email protected]>
  • Loading branch information
RandomLattice and andozw committed Apr 14, 2023
1 parent 3bab71c commit 3cc9272
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tools/tests_wycheproof_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
'''

import json
import hashlib
import urllib.request
import sys

filename_input = sys.argv[1]
Expand All @@ -19,7 +17,8 @@
num_groups = len(doc['testGroups'])

def to_c_array(x):
if x == "": return ""
if x == "":
return ""
s = ',0x'.join(a+b for a,b in zip(x[::2], x[1::2]))
return "0x" + s

Expand All @@ -43,18 +42,23 @@ def to_c_array(x):
sig_size = len(test_vector['sig']) // 2
msg_size = len(test_vector['msg']) // 2

if test_vector['result'] == "invalid": expected_verify = 0
elif test_vector['result'] == "valid": expected_verify = 1
else: raise ValueError("invalid result field")
if test_vector['result'] == "invalid":
expected_verify = 0
elif test_vector['result'] == "valid":
expected_verify = 1
else:
raise ValueError("invalid result field")

if num_vectors != 0 and sig_size != 0: signatures += ",\n "
if num_vectors != 0 and sig_size != 0:
signatures += ",\n "

new_msg = False
msg = to_c_array(test_vector['msg'])
msg_offset = offset_msg_running
# check for repeated msg
if msg not in cache_msgs.keys():
if num_vectors != 0 and msg_size != 0: messages += ",\n "
if num_vectors != 0 and msg_size != 0:
messages += ",\n "
cache_msgs[msg] = offset_msg_running
messages += msg
new_msg = True
Expand All @@ -66,7 +70,8 @@ def to_c_array(x):
pk_offset = offset_pk_running
# check for repeated pk
if pk not in cache_public_keys.keys():
if num_vectors != 0: public_keys += ",\n "
if num_vectors != 0:
public_keys += ",\n "
cache_public_keys[pk] = offset_pk_running
public_keys += pk
new_pk = True
Expand All @@ -83,8 +88,10 @@ def to_c_array(x):
offset_sig,
sig_size,
expected_verify) + " },\n"
if new_msg: offset_msg_running += msg_size
if new_pk: offset_pk_running += 65
if new_msg:
offset_msg_running += msg_size
if new_pk:
offset_pk_running += 65
offset_sig += sig_size
num_vectors += 1

Expand Down

0 comments on commit 3cc9272

Please sign in to comment.