Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename generic publickey import function #285

Merged
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions securesystemslib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,11 @@ def import_ecdsa_privatekey_from_file(filepath, password=None,



def import_public_keys_from_file(filepaths, key_types=None):
"""Import multiple public keys from files.
def import_publickeys_from_file(filepaths, key_types=None):
"""Imports multiple public keys from files.

NOTE: Use 'import_rsa_publickey_from_file' to specify any other than the
default signing schemes for an RSA key.

Arguments:
filepaths: A list of paths to public key files.
Expand All @@ -949,8 +952,8 @@ def import_public_keys_from_file(filepaths, key_types=None):

Raises:
TypeError: filepaths or key_types (if passed) is not iterable.
securesystemslib.exceptions.FormatError: key_types is passed and does not
have the same length as filepaths or contains an unsupported key type.
FormatError: key_types is passed and does not have the same length as
filepaths or contains an unsupported key type.
See import_ed25519_publickey_from_file, import_rsa_publickey_from_file and
import_ecdsa_publickey_from_file for other exceptions.

Expand All @@ -959,7 +962,7 @@ def import_public_keys_from_file(filepaths, key_types=None):

"""
if key_types is None:
key_types = [securesystemslib.KEY_TYPE_RSA] * len(filepaths)
key_types = [KEY_TYPE_RSA] * len(filepaths)

if len(key_types) != len(filepaths):
raise securesystemslib.exceptions.FormatError(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
generate_and_write_ecdsa_keypair,
import_ecdsa_publickey_from_file,
import_ecdsa_privatekey_from_file,
import_public_keys_from_file)
import_publickeys_from_file)



Expand Down Expand Up @@ -499,11 +499,11 @@ def test_ecdsa(self):



def test_import_public_keys_from_file(self):
def test_import_publickeys_from_file(self):
"""Test import multiple public keys with different types. """

# Successfully import key dict with one key per supported key type
key_dict = import_public_keys_from_file([
key_dict = import_publickeys_from_file([
self.path_rsa + ".pub",
self.path_ed25519 + ".pub",
self.path_ecdsa + ".pub"],
Expand All @@ -516,28 +516,28 @@ def test_import_public_keys_from_file(self):
)

# Successfully import default rsa key
key_dict = import_public_keys_from_file([self.path_rsa + ".pub"])
key_dict = import_publickeys_from_file([self.path_rsa + ".pub"])
ANY_PUBKEY_DICT_SCHEMA.check_match(key_dict)
RSAKEY_SCHEMA.check_match(
list(key_dict.values()).pop())

# Bad default rsa key type for ed25519
with self.assertRaises(Error):
import_public_keys_from_file([self.path_ed25519 + ".pub"])
import_publickeys_from_file([self.path_ed25519 + ".pub"])

# Bad ed25519 key type for rsa key
with self.assertRaises(Error):
import_public_keys_from_file(
import_publickeys_from_file(
[self.path_rsa + ".pub"], [KEY_TYPE_ED25519])

# Unsupported key type
with self.assertRaises(FormatError):
import_public_keys_from_file(
import_publickeys_from_file(
[self.path_ed25519 + ".pub"], ["KEY_TYPE_UNSUPPORTED"])

# Mismatching arguments lists lenghts
with self.assertRaises(FormatError):
import_public_keys_from_file(
import_publickeys_from_file(
[self.path_rsa + ".pub", self.path_ed25519 + ".pub"],
[KEY_TYPE_ED25519])

Expand Down