Skip to content

Commit f5f162f

Browse files
committed
Fix unsupported hash algo exception in GCPSigner
GCPSigner is expected to raise UnsupportedAlgorithmError, if the hash algorithm encoded in scheme is invalid. Switching from securesystemslib.hash to hashlib, requires wrapping and re-raising to maintain the expected behavior. This is a temporary solution until #766. Signed-off-by: Lukas Puehringer <[email protected]>
1 parent a275405 commit f5f162f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

securesystemslib/signer/_gcp_signer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ def _get_hash_algorithm(public_key: Key) -> str:
180180
)
181181

182182
# trigger UnsupportedAlgorithm if appropriate
183-
_ = hashlib.new(algo)
183+
# TODO: validate scheme/algo in constructor (#766)
184+
try:
185+
_ = hashlib.new(algo)
186+
except (ValueError, TypeError) as e:
187+
raise exceptions.UnsupportedAlgorithmError(algo) from e
188+
184189
return algo
185190

186191
def sign(self, payload: bytes) -> Signature:

0 commit comments

Comments
 (0)