File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from pyvalueobjects .abstract .nullablevalueobject import build_nullable
2+ from pyvalueobjects .security .sha256_hash import Sha256Hash
3+
4+ _nullable_cls = build_nullable (Sha256Hash )
5+
6+
7+ class NullableSha256Hash (_nullable_cls ):
8+
9+ def __init__ (self , value : str = None ):
10+ super ().__init__ (value )
Original file line number Diff line number Diff line change 1+ import re
2+
3+ from pyvalueobjects .errors .ValueObjectError import ValueObjectError
4+ from pyvalueobjects .strings .non_empty_string import NonEmptyString
5+
6+
7+ class Sha256Hash (NonEmptyString ):
8+
9+ __MATCHER = re .compile (r'^[a-fA-F0-9]{64}$' )
10+
11+ def __init__ (self , value : str ):
12+ super ().__init__ (value )
13+
14+ def _validate (self , value : str ):
15+ super ()._validate (value )
16+ try :
17+ is_correct = Sha256Hash .__MATCHER .match (value )
18+ if not is_correct :
19+ raise ValueObjectError ('Value must be a valid SHA256 hash (64 hexadecimal characters).' )
20+ except ValueError :
21+ raise ValueObjectError ('Value must be a valid SHA256 hash (64 hexadecimal characters).' )
You can’t perform that action at this time.
0 commit comments