Skip to content

Commit 9f20e28

Browse files
committed
Add hash name conversion
Signed-off-by: laurentsimon <laurentsimon@google.com>
1 parent 31c1cce commit 9f20e28

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sigstore/_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from cryptography.x509.oid import ExtendedKeyUsageOID, ExtensionOID
3636

3737
from sigstore.errors import Error
38+
from sigstore_protobuf_specs.dev.sigstore.common.v1 import HashAlgorithm
3839

3940
if sys.version_info < (3, 11):
4041
import importlib_resources as resources
@@ -158,6 +159,12 @@ def key_id(key: PublicKey) -> KeyID:
158159

159160
return KeyID(hashlib.sha256(public_bytes).digest())
160161

162+
def hazmat_digest_to_bundle(algo: str):
163+
lookup = {"sha256": HashAlgorithm.SHA2_256}
164+
if algo in lookup:
165+
return lookup[algo]
166+
return algo
167+
161168
def get_digest(
162169
input_: IO[bytes],
163170
algorithm_: Prehashed = None,

sigstore/verify/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
cert_is_leaf,
6464
cert_is_root_ca,
6565
get_digest,
66+
hazmat_digest_to_bundle,
6667
)
6768
from sigstore.errors import Error
6869
from sigstore.transparency import LogEntry, LogInclusionProof
@@ -518,7 +519,7 @@ def to_bundle(self) -> Bundle:
518519
),
519520
message_signature=MessageSignature(
520521
message_digest=HashOutput(
521-
algorithm=HashAlgorithm.SHA2_256,
522+
algorithm=hazmat_digest_to_bundle(self.digest_algorithm._algorithm.name),
522523
digest=self.input_digest,
523524
),
524525
signature=self.signature,

0 commit comments

Comments
 (0)