Skip to content

Commit

Permalink
secure-systems-lab#615 - rename _from_pem to _crypto_key
Browse files Browse the repository at this point in the history
Signed-off-by: E3E <[email protected]>
  • Loading branch information
NicholasTanz committed Jan 5, 2024
1 parent b94e647 commit 12bb4ff
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions securesystemslib/signer/_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ 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":
def _crypto_key(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!
"""
public_bytes = self.keyval["public"].encode("utf-8")
return load_pem_public_key(public_bytes)
Expand Down Expand Up @@ -376,7 +374,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 +384,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 12bb4ff

Please sign in to comment.