mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-24 06:02:44 +00:00
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:
parent
09e9872037
commit
001ec961c6
@ -40,7 +40,7 @@ KEYS = {
|
|||||||
|
|
||||||
def generate_der_file(curve_type: str, curve_or_bits: str):
|
def generate_der_file(curve_type: str, curve_or_bits: str):
|
||||||
if not os.path.exists(KEY_GEN):
|
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':
|
if curve_type == 'ec':
|
||||||
cob_param = 'ec_curve=' + curve_or_bits
|
cob_param = 'ec_curve=' + curve_or_bits
|
||||||
else:
|
else:
|
||||||
@ -66,13 +66,6 @@ def convert_der_to_c(array_name: str) -> str:
|
|||||||
|
|
||||||
return output_text
|
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():
|
def main():
|
||||||
# Remove intermediate and output files if already existing.
|
# Remove intermediate and output files if already existing.
|
||||||
if os.path.exists(OUTPUT_HEADER_FILE):
|
if os.path.exists(OUTPUT_HEADER_FILE):
|
||||||
@ -81,6 +74,13 @@ def main():
|
|||||||
os.remove(TMP_DER_FILE)
|
os.remove(TMP_DER_FILE)
|
||||||
|
|
||||||
output_file = open(OUTPUT_HEADER_FILE, 'at')
|
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
|
add_newline = False
|
||||||
for key in KEYS:
|
for key in KEYS:
|
||||||
@ -91,10 +91,8 @@ def main():
|
|||||||
# to the output header file.
|
# to the output header file.
|
||||||
if add_newline:
|
if add_newline:
|
||||||
output_file.write("\n")
|
output_file.write("\n")
|
||||||
output_file.write(write_header(key))
|
|
||||||
c_data = convert_der_to_c(key)
|
c_data = convert_der_to_c(key)
|
||||||
output_file.write(c_data)
|
output_file.write(c_data)
|
||||||
output_file.write(write_footer())
|
|
||||||
# Remove the temporary key file.
|
# Remove the temporary key file.
|
||||||
os.remove(TMP_DER_FILE)
|
os.remove(TMP_DER_FILE)
|
||||||
add_newline = True
|
add_newline = True
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user