mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-10-02 14:57:22 +00:00
scripts: generate_test_keys: allow multiple usage of the generated header
- declare all arrays and structures as static - add guards to the header file This allows multiple inclusions of the generated header file. Signed-off-by: Valerio Setti <[email protected]>
This commit is contained in:
@@ -15,7 +15,7 @@ from mbedtls_framework import build_tree
|
|||||||
BYTES_PER_LINE = 16
|
BYTES_PER_LINE = 16
|
||||||
|
|
||||||
def c_byte_array_literal_content(array_name: str, key_data: bytes) -> Iterator[str]:
|
def c_byte_array_literal_content(array_name: str, key_data: bytes) -> Iterator[str]:
|
||||||
yield 'const unsigned char '
|
yield 'static const unsigned char '
|
||||||
yield array_name
|
yield array_name
|
||||||
yield '[] = {'
|
yield '[] = {'
|
||||||
for index in range(0, len(key_data), BYTES_PER_LINE):
|
for index in range(0, len(key_data), BYTES_PER_LINE):
|
||||||
@@ -89,12 +89,23 @@ def get_look_up_table_entry(key_type: str, group_id_or_keybits: str,
|
|||||||
|
|
||||||
|
|
||||||
def write_output_file(output_file_name: str, arrays: str, look_up_table: str):
|
def write_output_file(output_file_name: str, arrays: str, look_up_table: str):
|
||||||
|
"""Write generated content to the output file"""
|
||||||
with open(output_file_name, 'wt') as output:
|
with open(output_file_name, 'wt') as output:
|
||||||
output.write("""\
|
output.write("""\
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* This file was automatically generated from framework/scripts/generate_test_keys.py.
|
* This file was automatically generated from framework/scripts/generate_test_keys.py.
|
||||||
* Please do not edit it manually.
|
* Please do not edit it manually.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef TEST_TEST_KEYS_H
|
||||||
|
#define TEST_TEST_KEYS_H
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_VERSION_MAJOR) || MBEDTLS_VERSION_MAJOR >= 4
|
||||||
|
#include <mbedtls/private/ecp.h>
|
||||||
|
#else
|
||||||
|
#include <mbedtls/ecp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
""")
|
""")
|
||||||
output.write(arrays)
|
output.write(arrays)
|
||||||
output.write("""
|
output.write("""
|
||||||
@@ -107,10 +118,18 @@ struct predefined_key_element {{
|
|||||||
size_t pub_key_len;
|
size_t pub_key_len;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
struct predefined_key_element predefined_keys[] = {{
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
|
#define UNUSED __attribute__((unused))
|
||||||
|
#else
|
||||||
|
#define UNUSED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct predefined_key_element predefined_keys[] UNUSED = {{
|
||||||
{}
|
{}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
#endif /* TEST_TEST_KEYS_H */
|
||||||
|
|
||||||
/* End of generated file */
|
/* End of generated file */
|
||||||
""".format(look_up_table))
|
""".format(look_up_table))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user