Skip to content

Commit

Permalink
Merge pull request #705 from NicholasTanz/renameFromPem
Browse files Browse the repository at this point in the history
#615 - rename _from_pem to _crypto_key
  • Loading branch information
jku authored Jan 5, 2024
2 parents b94e647 + 71f826c commit aa1cbdd
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions securesystemslib/signer/_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,8 @@ def from_dict(cls, keyid: str, key_dict: Dict[str, Any]) -> "SSlibKey":
def to_dict(self) -> Dict[str, Any]:
return self._to_dict()

def _from_pem(self) -> "PublicKeyTypes":
"""Helper to load public key instance from PEM-formatted keyval.
# FIXME: Sounds like it's an SSlibKey factory, but isn't. Should think
of a better name or refactor _verify!
"""
def _crypto_key(self) -> "PublicKeyTypes":
"""Helper to get a `cryptography` public key for this SSlibKey."""
public_bytes = self.keyval["public"].encode("utf-8")
return load_pem_public_key(public_bytes)

Expand Down Expand Up @@ -376,7 +372,7 @@ def _verify(self, signature: bytes, data: bytes) -> None:
"rsa-pkcs1v15-sha384",
"rsa-pkcs1v15-sha512",
]:
key = cast(RSAPublicKey, self._from_pem())
key = cast(RSAPublicKey, self._crypto_key())
padding_name, hash_name = self.scheme.split("-")[1:]
hash_algorithm = self._get_hash_algorithm(hash_name)
padding = self._get_rsa_padding(padding_name, hash_algorithm)
Expand All @@ -386,7 +382,7 @@ def _verify(self, signature: bytes, data: bytes) -> None:
"ecdsa-sha2-nistp256",
"ecdsa-sha2-nistp384",
]:
key = cast(EllipticCurvePublicKey, self._from_pem())
key = cast(EllipticCurvePublicKey, self._crypto_key())
hash_name = f"sha{self.scheme[-3:]}"
hash_algorithm = self._get_hash_algorithm(hash_name)
signature_algorithm = ECDSA(hash_algorithm)
Expand Down

0 comments on commit aa1cbdd

Please sign in to comment.