Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Consolidate on returning str in get_vk and get_sk
Browse files Browse the repository at this point in the history
  • Loading branch information
alwa-nordic committed Oct 16, 2019
1 parent 5b5e535 commit 74d1e64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nordicsemi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions nordicsemi/dfu/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand All @@ -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)
"""
Expand All @@ -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")

Expand Down

0 comments on commit 74d1e64

Please sign in to comment.