Fix: InvalidMRZKey error for TD1 overflow format

This commit is contained in:
ArmanKolozyan
2025-12-23 17:22:33 +01:00
committed by Justin Hernandez
parent 076ec4f537
commit 9ff8bef5a4

View File

@@ -119,9 +119,14 @@ class PassportReader: NSObject {
}
func pad( _ value : String, fieldLength:Int ) -> String {
// Pad out field lengths with < if they are too short
let paddedValue = (value + String(repeating: "<", count: fieldLength)).prefix(fieldLength)
return String(paddedValue)
// for values shorter than fieldLength, we pad with < characters
// for values equal to or longer than fieldLength, we use the value as-is (we don't truncate)
// this is critical for TD1 documents with overflow format where document numbers exceed 9 characters
if value.count >= fieldLength {
return value
}
let paddedValue = value + String(repeating: "<", count: fieldLength - value.count)
return paddedValue
}
func calcCheckSum( _ checkString : String ) -> Int {