diff --git a/CHANGELOG.md b/CHANGELOG.md index 656f4ee..2b34147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [1.0.9] - Unreleased - Updated dependencies +- Fixed issue with decoding lower case base32hex strings - Added support for MSCDI validation ## [1.0.8] - 2024-01-30 diff --git a/docs/changelog.md b/docs/changelog.md index 656f4ee..2b34147 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,7 @@ ## [1.0.9] - Unreleased - Updated dependencies +- Fixed issue with decoding lower case base32hex strings - Added support for MSCDI validation ## [1.0.8] - 2024-01-30 diff --git a/iscc_core/codec.py b/iscc_core/codec.py index 37b269d..2b373c7 100644 --- a/iscc_core/codec.py +++ b/iscc_core/codec.py @@ -320,7 +320,8 @@ def decode_base32hex(code): see: https://tools.ietf.org/html/rfc4648#page-10 """ - b32 = code.translate(hex_to_b32) + # Make sure we use upper-case version for translation + b32 = code.upper().translate(hex_to_b32) return decode_base32(b32) diff --git a/iscc_core/models.py b/iscc_core/models.py index dcf226f..0fca050 100644 --- a/iscc_core/models.py +++ b/iscc_core/models.py @@ -260,7 +260,7 @@ def rnd(cls, mt=None, st=None, bits=64, data=None): return cls((mt, st, vs, ln_code, data)) @property - def mc_bytes(self): + def mc_bytes(self) -> bytes: """ISCC header + body with multicodec prefix.""" return MC_PREFIX + self.bytes @@ -276,7 +276,7 @@ def mf_base32(self) -> str: @property def mf_base32hex(self) -> str: - """Multiformats base32 encoded.""" + """Multiformats base32hex encoded.""" return "v" + encode_base32hex(self.mc_bytes).lower() @property diff --git a/tests/test_codec.py b/tests/test_codec.py index 89e0c4f..555fe28 100644 --- a/tests/test_codec.py +++ b/tests/test_codec.py @@ -560,6 +560,13 @@ def test_encode_base32hex(): assert ic.encode_base32hex(b"hello world") == "D1IMOR3F41RMUSJCCG" +def test_base32hex_roundtrip_lower(): + data = bytes.fromhex("cc01cd9d2b7d247a8333f7b0b7d2cda8056c3d15eef738c1962e9148624feac1c14f") + expected_b32hex = "PG0SR79BFKI7L0PJUUOBFKMDL02MOF8LTRRJHGCM5Q8KGOIFTB0S2JO" + assert ic.encode_base32hex(data) == "PG0SR79BFKI7L0PJUUOBFKMDL02MOF8LTRRJHGCM5Q8KGOIFTB0S2JO" + assert ic.decode_base32hex(expected_b32hex.lower()) == data + + def test_decode_base32hex(): assert ic.decode_base32hex("D1IMOR3F41RMUSJCCG") == b"hello world"