Skip to content

Commit bdae258

Browse files
author
Michael Schlenker
committed
Add the weird legacy blake2256 etc. cases back in.
Signed-off-by: Michael Schlenker <[email protected]>
1 parent d9c4405 commit bdae258

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cyclonedx/model/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def from_composite_str(composite_hash: str) -> 'HashType':
420420
421421
Valid case insensitive prefixes are:
422422
`md5`, `sha1`, `sha256`, `sha384`, `sha512`, `blake2b256`, `blake2b384`, `blake2b512`,
423-
`sha3-256`, `sha3-384`, `sha3-512`,
423+
`blake2256`, `blake2384`, `blake2512`, `sha3-256`, `sha3-384`, `sha3-512`,
424424
`blake3`.
425425
426426
Raises:
@@ -458,6 +458,11 @@ def from_composite_str(composite_hash: str) -> 'HashType':
458458
alg=getattr(HashAlgorithm, f'BLAKE2B_{algorithm_prefix[7:]}'),
459459
content=parts[1].lower()
460460
)
461+
elif algorithm_prefix[0:6] == 'blake2':
462+
return HashType(
463+
alg=getattr(HashAlgorithm, f'BLAKE2B_{algorithm_prefix[6:]}'),
464+
content=parts[1].lower()
465+
)
461466
elif algorithm_prefix[0:6] == 'blake3':
462467
return HashType(
463468
alg=HashAlgorithm.BLAKE3,

tests/test_model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ def test_hash_type_from_hashlib_alg_throws_on_unknown(self) -> None:
273273
HashAlgorithm.BLAKE2B_512,
274274
'6d518ac5c7a022e954ecb21b8bf68d7f5c52e3c3579cd96f3bde4f76daaaa69a'
275275
'96a5eee268fb8fa2745930c37f0672424136b538878474bc4f586a63e13ae23f'),
276+
('blake2512',
277+
'blake2512:6d518ac5c7a022e954ecb21b8bf68d7f5c52e3c3579cd96f3bde4'
278+
'f76daaaa69a96a5eee268fb8fa2745930c37f0672424136b538878474bc4f586a63e13ae23f',
279+
HashAlgorithm.BLAKE2B_512,
280+
'6d518ac5c7a022e954ecb21b8bf68d7f5c52e3c3579cd96f3bde4f76daaaa69a'
281+
'96a5eee268fb8fa2745930c37f0672424136b538878474bc4f586a63e13ae23f'),
276282
)
277283
def test_hash_type_from_composite_str(self, composite: str, e_alg: HashAlgorithm, e_content: str) -> None:
278284
h = HashType.from_composite_str(composite)

0 commit comments

Comments
 (0)