diff --git a/CHANGELOG.md b/CHANGELOG.md index e7bec2c..656f4ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [1.0.9] - Unreleased - Updated dependencies +- Added support for MSCDI validation ## [1.0.8] - 2024-01-30 - Added implementors guide to README.md diff --git a/docs/changelog.md b/docs/changelog.md index e7bec2c..656f4ee 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,7 @@ ## [1.0.9] - Unreleased - Updated dependencies +- Added support for MSCDI validation ## [1.0.8] - 2024-01-30 - Added implementors guide to README.md diff --git a/iscc_core/codec.py b/iscc_core/codec.py index 51d6ed3..37b269d 100644 --- a/iscc_core/codec.py +++ b/iscc_core/codec.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import math -import re import uvarint from typing import List, Tuple import base58 @@ -511,10 +510,10 @@ def iscc_validate(iscc, strict=True): """ # Basic regex validation - match = re.match("^ISCC:[A-Z2-7]{10,60}$", iscc) + match = CANONICAL_REGEX.match(iscc) if not match: if strict: - raise ValueError("ISCC string does not match ^ISCC:[A-Z2-7]{10,60}$") + raise ValueError("ISCC string does not match ^ISCC:[A-Z2-7]{10,68}$") else: return False diff --git a/iscc_core/constants.py b/iscc_core/constants.py index 2fc9e9d..7e9f16f 100644 --- a/iscc_core/constants.py +++ b/iscc_core/constants.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import re import enum from typing import Tuple, Union @@ -171,6 +172,7 @@ class LN(enum.IntEnum): L192 = 192 L224 = 224 L256 = 256 + L320 = 320 class MULTIBASE(str, enum.Enum): @@ -245,3 +247,5 @@ class MULTIBASE(str, enum.Enum): "MM", "OA", ] + +CANONICAL_REGEX = re.compile("^ISCC:[A-Z2-7]{10,68}$") diff --git a/tests/test_codec.py b/tests/test_codec.py index fd35b93..89e0c4f 100644 --- a/tests/test_codec.py +++ b/tests/test_codec.py @@ -637,3 +637,12 @@ def test_iscc_validate_bad_length(): with pytest.raises(ValueError) as excinfo: ic.iscc_validate(sample, strict=True) assert str(excinfo.value) == "Header expects 32 but got 26 bytes" + + +def test_iscc_validate_mscdi(): + sample = "ISCC:KEDRRHYRYJ7XELW7HAO5FFGQRX75HJUKSUSZVWTTRNHTF2YL5SKP7XIUFXM4KMKXEZZA" + assert ic.iscc_validate(sample, strict=False) is True + assert ic.iscc_validate(sample, strict=True) is True + with pytest.raises(ValueError) as excinfo: + ic.iscc_validate(sample + "A", strict=True) + assert str(excinfo.value) == "ISCC string does not match ^ISCC:[A-Z2-7]{10,68}$"