Commit ed8d68af authored by Bence Balogh's avatar Bence Balogh Committed by Dávid Vincze
Browse files

imgtool: Add raw output option



Signed-off-by: default avatarDávid Házi <david.hazi@arm.com>
Signed-off-by: default avatarBence Balogh <bence.balogh@arm.com>
Change-Id: Ia7f385e5e1b0471aae7693baa54e9a385ad3ae3f
parent 367aefbe
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,13 @@ class KeyClass(object):
                len_format="const unsigned int {}_pub_key_len = {{}};".format(self.shortname()),
                len_format="const unsigned int {}_pub_key_len = {{}};".format(self.shortname()),
                file=file)
                file=file)


    def emit_raw_public(self, file=sys.stdout):
        if file and file is not sys.stdout:
            with open(file, 'wb') as file:
                file.write(self.get_public_bytes())
        else:
            sys.stdout.buffer.write(self.get_public_bytes())

    def emit_rust_public(self, file=sys.stdout):
    def emit_rust_public(self, file=sys.stdout):
        self._emit(
        self._emit(
                header="static {}_PUB_KEY: &[u8] = &[".format(self.shortname().upper()),
                header="static {}_PUB_KEY: &[u8] = &[".format(self.shortname().upper()),
+3 −1
Original line number Original line Diff line number Diff line
@@ -61,7 +61,7 @@ def gen_x25519(keyfile, passwd):




valid_langs = ['c', 'rust']
valid_langs = ['c', 'rust']
valid_encodings = ['lang-c', 'lang-rust', 'pem']
valid_encodings = ['lang-c', 'lang-rust', 'pem', 'raw']
keygens = {
keygens = {
    'rsa-2048':   gen_rsa2048,
    'rsa-2048':   gen_rsa2048,
    'rsa-3072':   gen_rsa3072,
    'rsa-3072':   gen_rsa3072,
@@ -152,6 +152,8 @@ def getpub(key, encoding, lang, output):
        key.emit_rust_public(file=output)
        key.emit_rust_public(file=output)
    elif encoding == 'pem':
    elif encoding == 'pem':
        key.emit_public_pem(file=output)
        key.emit_public_pem(file=output)
    elif encoding == 'raw':
        key.emit_raw_public(file=output)
    else:
    else:
        raise click.UsageError()
        raise click.UsageError()