Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions securesystemslib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def import_rsa_privatekey_from_file(filepath, password=None,



def import_rsa_publickey_from_file(filepath):
def import_rsa_publickey_from_file(filepath, scheme='rsassa-pss-sha256'):
"""
<Purpose>
Import the RSA key stored in 'filepath'. The key object returned is in the
Expand All @@ -366,6 +366,9 @@ def import_rsa_publickey_from_file(filepath):
filepath:
<filepath>.pub file, an RSA PEM file.

scheme:
The signature scheme used by the imported key.

<Exceptions>
securesystemslib.exceptions.FormatError, if 'filepath' is improperly
formatted.
Expand All @@ -386,14 +389,18 @@ def import_rsa_publickey_from_file(filepath):
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
securesystemslib.formats.PATH_SCHEMA.check_match(filepath)

# Is 'scheme' properly formatted?
securesystemslib.formats.RSA_SCHEME_SCHEMA.check_match(scheme)

# Read the contents of the key file that should be in PEM format and contains
# the public portion of the RSA key.
with open(filepath, 'rb') as file_object:
rsa_pubkey_pem = file_object.read().decode('utf-8')

# Convert 'rsa_pubkey_pem' to 'securesystemslib.formats.RSAKEY_SCHEMA' format.
try:
rsakey_dict = securesystemslib.keys.import_rsakey_from_public_pem(rsa_pubkey_pem)
rsakey_dict = securesystemslib.keys.import_rsakey_from_public_pem(
rsa_pubkey_pem, scheme)

except securesystemslib.exceptions.FormatError as e:
raise securesystemslib.exceptions.Error('Cannot import improperly formatted'
Expand Down