generate_test_keys.py: minor improvements

- remove BEGIN_FILE/END_FILE lines from output header file.
- add single disclaimer at the beginning of the file instead
  of having it repeated for every array.
- improved exception message for missing key generation program.

This commits also regenerates "test_keys.h" in order to fully
comply with the new format.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-04-03 13:42:20 +02:00
parent 26bc9c2fb8
commit 3e22bf2a31
2 changed files with 641 additions and 692 deletions

View File

@ -40,7 +40,7 @@ KEYS = {
def generate_der_file(curve_type: str, curve_or_bits: str):
if not os.path.exists(KEY_GEN):
raise Exception("Key generation program does not exist.")
raise Exception(KEY_GEN + " does not exist. Please build it before running this script.")
if curve_type == 'ec':
cob_param = 'ec_curve=' + curve_or_bits
else:
@ -66,13 +66,6 @@ def convert_der_to_c(array_name: str) -> str:
return output_text
def write_header(macro_name: str):
return ("/* This macro was generated from tests/scripts/generate_test_keys.py */\n" +
"/* BEGIN FILE string macro {} */\n".format(macro_name))
def write_footer():
return "/* END FILE */\n"
def main():
# Remove intermediate and output files if already existing.
if os.path.exists(OUTPUT_HEADER_FILE):
@ -81,6 +74,13 @@ def main():
os.remove(TMP_DER_FILE)
output_file = open(OUTPUT_HEADER_FILE, 'at')
output_file.write(
"/*********************************************************************************\n" +
" * This file was automatically generated from tests/scripts/generate_test_keys.py.\n" +
" * Please do not edit it manually.\n" +
" *********************************************************************************/\n" +
"\n"
)
add_newline = False
for key in KEYS:
@ -91,10 +91,8 @@ def main():
# to the output header file.
if add_newline:
output_file.write("\n")
output_file.write(write_header(key))
c_data = convert_der_to_c(key)
output_file.write(c_data)
output_file.write(write_footer())
# Remove the temporary key file.
os.remove(TMP_DER_FILE)
add_newline = True

File diff suppressed because it is too large Load Diff