Skip to content

Commit

Permalink
Merge c875b7e into 8482f2c
Browse files Browse the repository at this point in the history
  • Loading branch information
avelichka committed Aug 26, 2021
2 parents 8482f2c + c875b7e commit 49bf780
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_api.py
Expand Up @@ -54,6 +54,10 @@
Signature
)

from securesystemslib.keys import (
generate_ed25519_key
)

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -421,6 +425,14 @@ def test_metadata_verify_delegate(self):
root.verify_delegate('snapshot', snapshot)


def test_key_class(self):
# Test if from_securesystemslib_key removes the private key from keyval
# of a securesystemslib key dictionary.
sslib_key = generate_ed25519_key()
key = Key.from_securesystemslib_key(sslib_key)
self.assertFalse('private' in key.keyval.keys())


def test_metadata_root(self):
root_path = os.path.join(
self.repo_dir, 'metadata', 'root.json')
Expand Down
18 changes: 18 additions & 0 deletions tuf/api/metadata.py
Expand Up @@ -562,6 +562,24 @@ def to_securesystemslib_key(self) -> Dict[str, Any]:
"keyval": self.keyval,
}

@classmethod
def from_securesystemslib_key(cls, key_dict: Dict[str, Any]) -> "Key":
"""
Creates a Key object from a securesystemlib key dict representation
removing the private key from keyval.
"""
key_meta = sslib_keys.format_keyval_to_metadata(
key_dict["keytype"],
key_dict["scheme"],
key_dict["keyval"],
)
return cls(
key_dict["keyid"],
key_meta["keytype"],
key_meta["scheme"],
key_meta["keyval"],
)

def verify_signature(
self,
metadata: Metadata,
Expand Down

0 comments on commit 49bf780

Please sign in to comment.