Skip to content

Commit e661611

Browse files
committed
fix: error handling
1 parent c089290 commit e661611

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

pymdoccbor/mdoc/issuersigned.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from pymdoccbor.mso.verifier import MsoVerifier
55

6-
76
class IssuerSigned:
87
"""
98
nameSpaces provides the definition within which the data elements of
@@ -22,7 +21,7 @@ class IssuerSigned:
2221
]
2322
"""
2423

25-
def __init__(self, nameSpaces: dict, issuerAuth: Union[dict, bytes]) -> None:
24+
def __init__(self, nameSpaces: dict, issuerAuth: Union[cbor2.CBORTag, dict, bytes]) -> None:
2625
"""
2726
Initialize the IssuerSigned object
2827
@@ -32,6 +31,9 @@ def __init__(self, nameSpaces: dict, issuerAuth: Union[dict, bytes]) -> None:
3231

3332
self.namespaces: dict = nameSpaces
3433

34+
if not issuerAuth:
35+
raise ValueError("issuerAuth must be provided")
36+
3537
# if isinstance(ia, dict):
3638
self.issuer_auth = MsoVerifier(issuerAuth)
3739

pymdoccbor/mdoc/verifier.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ def __init__(self, docType: str, issuerSigned: dict, deviceSigned: dict = {}) ->
2929
:param deviceSigned: dict: the deviceSigned info
3030
"""
3131

32+
if not docType:
33+
raise ValueError("You must provide a document type")
34+
3235
self.doctype: str = docType # eg: 'org.iso.18013.5.1.mDL'
36+
37+
if not issuerSigned:
38+
raise ValueError("You must provide a signed document")
39+
3340
self.issuersigned: List[IssuerSigned] = IssuerSigned(**issuerSigned)
3441
self.is_valid = False
3542
self.devicesigned: dict = deviceSigned

pymdoccbor/mso/issuer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def __init__(
7373
raise ValueError("private_key must be a dict or CoseKey object")
7474
else:
7575
raise MsoPrivateKeyRequired("MSO Writer requires a valid private key")
76+
77+
if not validity:
78+
raise ValueError("validity must be present")
79+
80+
if not alg:
81+
raise ValueError("alg must be present")
7682

7783
self.data: dict = data
7884
self.hash_map: dict = {}

0 commit comments

Comments
 (0)