Skip to content

Commit

Permalink
Add support for MSCDI validation
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Feb 8, 2024
1 parent ee57754 commit 7447f86
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions iscc_core/codec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import math
import re
import uvarint
from typing import List, Tuple
import base58
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions iscc_core/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import re
import enum
from typing import Tuple, Union

Expand Down Expand Up @@ -171,6 +172,7 @@ class LN(enum.IntEnum):
L192 = 192
L224 = 224
L256 = 256
L320 = 320


class MULTIBASE(str, enum.Enum):
Expand Down Expand Up @@ -245,3 +247,5 @@ class MULTIBASE(str, enum.Enum):
"MM",
"OA",
]

CANONICAL_REGEX = re.compile("^ISCC:[A-Z2-7]{10,68}$")
9 changes: 9 additions & 0 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}$"

0 comments on commit 7447f86

Please sign in to comment.