Skip to content

Commit

Permalink
Rename generic publickey import function
Browse files Browse the repository at this point in the history
Rename "_public_key_" to "_publickey_" for consistency with other
interface key import functions.

This commit also fixes a typo in an error message, removes
unnecessary module paths and adds a note to the function docstring
to inform about the shortcoming of the generic function.
  • Loading branch information
lukpueh committed Oct 13, 2020
1 parent 0ec854b commit d7dfca6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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

0 comments on commit d7dfca6

Please sign in to comment.