Arg0s1080 / mrz

Machine Readable Zone generator and checker for official travel documents sizes 1, 2, 3, MRVA and MRVB (Passports, Visas, national id cards and other travel documents)
GNU General Public License v3.0
328 stars 122 forks source link

Empty optional data field and empty optional data hash in TD3 format will result in a invalid hash in the TD3CodeChecker #34

Closed KlaasJelmer closed 3 years ago

KlaasJelmer commented 3 years ago

Hi!

I have a Swiss passport with a MRZ in the TD3 format. On this document no optional data is used, hence its MRZ value is <<<<<<<<<<<<<<. The corresponding optional data hash is <.

I would expect that this would result in a valid MRZ readout, but this seems not the case. The empty values are not recognized as a valid value-hash pair: hash_is_ok("<<<<<<<<<<<<<<", "<") returns False. This in turn causes TD3CodeChecker(mrz) to cast to a False boolean.

Arg0s1080 commented 3 years ago

Hi there!

Could you give an example?

I have done the following test:

from mrz.checker.td3 import TD3CodeChecker

# Case 1: Optional Data "<<<<<<<<<<<<<<", hash "0"
check1 = ("P<GB<MARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
          "980XG47<<9GBR8501019F2612281<<<<<<<<<<<<<<06")

# Case 2 Optional Data "<<<<<<<<<<<<<<", hash "<"
check2 = ("P<GB<MARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
          "980XG47<<9GBR8501019F2612281<<<<<<<<<<<<<<<6")

# Case 3 Optional Data "<<<<<<<<<<<<<<", hash "7"
check3 = ("P<GB<MARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
          "980XG47<<9GBR8501019F2612281<<<<<<<<<<<<<<76")

print(TD3CodeChecker(check1))
print(TD3CodeChecker(check2))
print(TD3CodeChecker(check3))

And its output is:

True 
True
False

Is true that has_is_ok() function returns False, but that problem as it happened later was solved in optional_data_hash property.

I recognize that as you suggest this problem should be solved in hash_is_ok() (i take note)

Greetings