Skip to content

Commit

Permalink
GCPSigner: Add exception for unsupported keys
Browse files Browse the repository at this point in the history
This seems correct-er and makes pylint happier.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
jku committed May 21, 2024
1 parent 603b461 commit f61cf1a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion securesystemslib/signer/_gcp_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ def _get_hash_algorithm(public_key: Key) -> str:
if public_key.keytype == "rsa":
# hash algorithm is encoded as last scheme portion
algo = public_key.scheme.split("-")[-1]
if public_key.keytype in [
elif public_key.keytype in [
"ecdsa",
"ecdsa-sha2-nistp256",
"ecdsa-sha2-nistp384",
]:
# nistp256 uses sha-256, nistp384 uses sha-384
bits = public_key.scheme.split("-nistp")[-1]
algo = f"sha{bits}"
else:
raise exceptions.UnsupportedAlgorithmError(
f"Unsupported key type {public_key.keytype} in key {public_key.keyid}"
)

# trigger UnsupportedAlgorithm if appropriate
_ = sslib_hash.digest(algo)
Expand Down

0 comments on commit f61cf1a

Please sign in to comment.