From 74d1e64a2e1acbbbb2193bc8c9d834c7c6386789 Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Wed, 16 Oct 2019 10:49:48 +0200 Subject: [PATCH] Consolidate on returning str in get_vk and get_sk --- nordicsemi/__main__.py | 2 +- nordicsemi/dfu/signing.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nordicsemi/__main__.py b/nordicsemi/__main__.py index 6a07abd..1df882d 100755 --- a/nordicsemi/__main__.py +++ b/nordicsemi/__main__.py @@ -454,7 +454,7 @@ def display(key_file, key, format, out_file): if key == "pk": kstr = signer.get_vk(format, dbg) elif key == "sk": - kstr = b"\nWARNING: Security risk! Do not share the private key.\n\n" + kstr = "\nWARNING: Security risk! Do not share the private key.\n\n" kstr = kstr + signer.get_sk(format, dbg) if not out_file: diff --git a/nordicsemi/dfu/signing.py b/nordicsemi/dfu/signing.py index e9c67ac..86ff953 100644 --- a/nordicsemi/dfu/signing.py +++ b/nordicsemi/dfu/signing.py @@ -121,7 +121,7 @@ def verify(self, init_packet, signature): return True - def get_vk(self, output_type, dbg): + def get_vk(self, output_type, dbg) -> str: """ Get public key (as hex, code or pem) """ @@ -135,11 +135,12 @@ def get_vk(self, output_type, dbg): elif output_type == 'code': return self.get_vk_code(dbg) elif output_type == 'pem': - return self.get_vk_pem() + # Return pem as str to conform in type with the other cases. + return self.get_vk_pem().decode() else: raise InvalidArgumentException("Invalid argument. Can't get key") - def get_sk(self, output_type, dbg): + def get_sk(self, output_type, dbg) -> str: """ Get private key (as hex, code or pem) """ @@ -153,7 +154,8 @@ def get_sk(self, output_type, dbg): elif output_type == 'code': raise InvalidArgumentException("Private key cannot be shown as code") elif output_type == 'pem': - return self.sk.to_pem() + # Return pem as str to conform in type with the other cases. + return self.sk.to_pem().decode() else: raise InvalidArgumentException("Invalid argument. Can't get key")