Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update identifier validation in _fields.py #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Hc747
Copy link

@Hc747 Hc747 commented Oct 2, 2020

Addresses use case where the first line of a valid TD3 MRZ is structured as so:

P<XXXAA<<BBBBBB<<CCCCC<DD<<<<<<<<<<<<<<<<<<<

Whereby the 'A' component is the primary identifier (surname) and the 'B', 'C' and 'D' components are the secondary identifier (name).

Addresses use case where the first line of a valid TD3 MRZ is structured as so:

P<XXXAA<<BBBBBB<<CCCCC<DD<<<<<<<<<<<<<<<<<<<

Whereby the 'A' component is the primary identifier (surname) and the 'B', 'C' and 'D' components are the secondary identifier (name).
@Hc747
Copy link
Author

Hc747 commented Oct 2, 2020

Please let me know if you're okay with merging this @Arg0s1080. Hope all is well on your end!

@Arg0s1080
Copy link
Owner

Please let me know if you're okay with merging this @Arg0s1080. Hope all is well on your end!

Hi!

Hello

I promise to try to review it this weekend

@Arg0s1080 Arg0s1080 self-assigned this Oct 2, 2020
@Arg0s1080 Arg0s1080 added the pending Something is pending verification label Oct 2, 2020
@Hc747
Copy link
Author

Hc747 commented Oct 3, 2020

Please let me know if you're okay with merging this @Arg0s1080. Hope all is well on your end!

Hi!

Hello

I promise to try to review it this weekend

Thank you - no rush! Let me know if there's anything you'd like changed!

@Hc747
Copy link
Author

Hc747 commented Oct 9, 2020

Bump @Arg0s1080 :p

@Arg0s1080
Copy link
Owner

Hi again:

Sorry, I'm should have said "next weekend"

I dont know if i understand your problem well, but....

The approach you propose is no-valid.

ICAO specs say:

9303-3

4.6 Convention for Writing the Name of the Holder

[...]

The primary identifier, using the Latin character transliteration (if applicable), shall be written in the MRZ as specified in the form factor specific Parts 4 to 7 of Doc 9303. The primary identifier shall be followed by two filler characters (<<). The secondary identifier, using the Latin character transliteration (if applicable), shall be written starting in the character
position immediately following the two filler characters.

If the primary or secondary identifiers have more than one name component, each component shall be separated by a single filler character (<).

Filler characters (<) should be inserted immediately following the final secondary identifier (or following the primary identifier in the case of a name having only a primary identifier) through to the last character position in the machine readable line.

So.. following your sample, its structure should be:

P<XXXAA<<BBBBBB<CCCCCC<DD<<<<<<<<<<<<<<<<<<<

instead:
P<XXXAA<<BBBBBB<<CCCCC<DD<<<<<<<<<<<<<<<<<<<

For example:

More than 2 identifiers:
Primary: AA
Secondary: BBBBBB
Tertiary: CCCCCC DD

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

from mrz.checker.td3 import TD3CodeChecker


check = TD3CodeChecker("P<XXXAA<<BBBBBB<<CCCCC<DD<<<<<<<<<<<<<<<<<<<\n"
                       "ZE000509<9XXX8501019F2301147<<<<<<<<<<<<<<08")


print("Result:")
print(bool(check))

print()
print("Detected errors:")
errors = check.report.errors
if len(errors) > 0:
    print(check.report.errors)
else:
    print("None")

Output:

Result: False

Detected errors:
['more than two identifiers', 'false identifier']

If we repair the full name using only 2 identifiers:

Primary: AA
Secondary: BBBBBB CCCCC DD

from mrz.checker.td3 import TD3CodeChecker


check = TD3CodeChecker("P<XXXAA<<BBBBBB<CCCCCC<DD<<<<<<<<<<<<<<<<<<<\n"
                       "ZE000509<9XXX8501019F2301147<<<<<<<<<<<<<<08")


print("Result:")
print(bool(check))

print()
print("Detected errors:")
errors = check.report.errors
if len(errors) > 0:
    print(check.report.errors)
else:
    print("None")

Output:

Result:
True

Detected errors:
None

Sorry for the delay and BR

PS: If I have understood something bad tell me

@Arg0s1080 Arg0s1080 removed the pending Something is pending verification label Oct 10, 2020
@Hc747
Copy link
Author

Hc747 commented Oct 12, 2020

@Arg0s1080 I don't believe you've misunderstood anything! :)
Strange however, because I've received an official passport document that does not adhere to this standard and therefore cannot be parsed by this library. The document was in the format specified in the original post of this PR.

@Arg0s1080
Copy link
Owner

It's pretty weird. ICAO specs are quite flexible and leave many things at the discretion of the issuing State, but others are very strict. Its also not very rare to find organizations that do not meet specs.

Out of curiosity, may I know what country it is?

You can modify the code however you want, but the correct thing would be to add a "special case" (India had a similar problem... I think I remember that there were identifiers that started with << or something like that) creating a class that overwrite "the official ones"

Due to a design problem, the format of the class name must:

  • Start with TD1, TD2, TD3 OR Passport
  • Finish with "CodeChecker" or CodeGenerator

For example TD1MyNewClassCodeGenertor or PassportOtherClassNameCodeChecker

@Hc747
Copy link
Author

Hc747 commented Oct 16, 2020

Thanks very much for the feedback and solution; will go with that approach. The document was an Indonesian passport document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants