ISO 18013-5 specifies that when a Device Response has status != 0, documents may contain an errors field describing which elements were not available or could not be returned.
Example from real-world France Identité CNI:
{
'version': '1.0',
'documents': [{
'docType': 'eu.europa.ec.eudi.pid.1',
'issuerSigned': {...},
'errors': {
'eu.europa.ec.eudi.pid.1': {
'some_element': 1 # Error code
}
}
}],
'status': 20 # Elements not present
}Previously, pyMDOC-CBOR v1.0.1 would raise:
TypeError: MobileDocument.__init__() got an unexpected keyword argument 'errors'
Added support for the optional errors parameter in MobileDocument.__init__():
- Updated
__init__signature:
def __init__(self, docType: str, issuerSigned: dict, deviceSigned: dict = {}, errors: dict = None) -> None:
# ...
self.errors: dict = errors if errors is not None else {}- Updated
dump()method to include errors when present:
def dump(self) -> bytes:
doc_dict = {
'docType': self.doctype,
'issuerSigned': self.issuersigned.dumps()
}
# Include errors field if present (ISO 18013-5 status != 0)
if self.errors:
doc_dict['errors'] = self.errors
return cbor2.dumps(cbor2.CBORTag(24, value=doc_dict))✅ Fully backward compatible:
errorsparameter is optional (defaults toNone)- When
errorsis empty orNone, it's not included indump()output - All existing tests pass (36/36)
Added comprehensive test suite in pymdoccbor/tests/test_09_errors_field.py:
- ✅
test_mobile_document_with_errors_field- Accepts errors field - ✅
test_mobile_document_without_errors_field- Works without errors (backward compat) - ✅
test_mobile_document_dump_with_errors- Includes errors in dump when present - ✅
test_mobile_document_dump_without_errors- Excludes errors from dump when empty
All tests pass: 36/36 passed
from pymdoccbor.mdoc.verifier import MobileDocument
document = {
'docType': 'eu.europa.ec.eudi.pid.1',
'issuerSigned': {...},
'errors': {
'eu.europa.ec.eudi.pid.1': {
'missing_element': 1
}
}
}
doc = MobileDocument(**document) # ✅ Works now!
print(doc.errors) # {'eu.europa.ec.eudi.pid.1': {'missing_element': 1}}document = {
'docType': 'eu.europa.ec.eudi.pid.1',
'issuerSigned': {...}
}
doc = MobileDocument(**document) # ✅ Still works
print(doc.errors) # {}From ISO/IEC 18013-5:2021, section 8.3.2.1.2.2:
status: Status code indicating the result of the request
- 0: OK
- 10: General error
- 20: CBOR decoding error
- ...
When status != 0, the
errorsfield MAY be present to provide details about which elements could not be returned.
Branch: fix/support-errors-field