diff options
| author | JF <jf@codingfield.com> | 2021-03-07 18:45:35 +0100 |
|---|---|---|
| committer | Gitea <gitea@fake.local> | 2021-03-07 18:45:35 +0100 |
| commit | c5dc4c55a79e0e3393df22e77825f24b6130a0bb (patch) | |
| tree | 6f81eb191aa0c749cbef9b856d43ed4546302802 /tools/mcuboot/imgtool/keys/general.py | |
| parent | ada942535718d48eec37cca4f50d678e7201dc67 (diff) | |
| parent | 5845fd98ba68e12f1e57d50ed06abd7ccf47e029 (diff) | |
Merge branch 'recovery-firmware' of JF/PineTime into develop
Diffstat (limited to 'tools/mcuboot/imgtool/keys/general.py')
| -rw-r--r-- | tools/mcuboot/imgtool/keys/general.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/mcuboot/imgtool/keys/general.py b/tools/mcuboot/imgtool/keys/general.py new file mode 100644 index 00000000..ce7a2d26 --- /dev/null +++ b/tools/mcuboot/imgtool/keys/general.py @@ -0,0 +1,45 @@ +"""General key class.""" + +import sys + +AUTOGEN_MESSAGE = "/* Autogenerated by imgtool.py, do not edit. */" + +class KeyClass(object): + def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout, len_format=None): + print(AUTOGEN_MESSAGE, file=file) + print(header, end='', file=file) + for count, b in enumerate(encoded_bytes): + if count % 8 == 0: + print("\n" + indent, end='', file=file) + else: + print(" ", end='', file=file) + print("0x{:02x},".format(b), end='', file=file) + print("\n" + trailer, file=file) + if len_format is not None: + print(len_format.format(len(encoded_bytes)), file=file) + + def emit_c_public(self, file=sys.stdout): + self._emit( + header="const unsigned char {}_pub_key[] = {{".format(self.shortname()), + trailer="};", + encoded_bytes=self.get_public_bytes(), + indent=" ", + len_format="const unsigned int {}_pub_key_len = {{}};".format(self.shortname()), + file=file) + + def emit_rust_public(self, file=sys.stdout): + self._emit( + header="static {}_PUB_KEY: &'static [u8] = &[".format(self.shortname().upper()), + trailer="];", + encoded_bytes=self.get_public_bytes(), + indent=" ", + file=file) + + def emit_private(self, minimal, file=sys.stdout): + self._emit( + header="const unsigned char enc_priv_key[] = {", + trailer="};", + encoded_bytes=self.get_private_bytes(minimal), + indent=" ", + len_format="const unsigned int enc_priv_key_len = {};", + file=file) |
