Class MRZInfo

  • All Implemented Interfaces:
    Serializable, LDSElement

    public class MRZInfo
    extends AbstractLDSInfo
    Data structure for storing the MRZ information as found in DG1. Based on ICAO Doc 9303 (Seventh edition) part 4 (TD3), part 5 (TD1), part 6 (TD2), and part 7 (MRV-A, MRV-B).
    Version:
    $Revision: 1864 $
    Author:
    The JMRTD team ([email protected])
    See Also:
    Serialized Form
    • Field Detail

      • DOC_TYPE_UNSPECIFIED

        public static final int DOC_TYPE_UNSPECIFIED
        Unspecified document type (do not use, choose ID1 or ID3).
        See Also:
        Constant Field Values
      • DOC_TYPE_ID1

        public static final int DOC_TYPE_ID1
        ID1 document type for credit card sized identity cards. Specifies a 3-line MRZ, 30 characters wide.
        See Also:
        Constant Field Values
      • DOC_TYPE_ID2

        public static final int DOC_TYPE_ID2
        ID2 document type. Specifies a 2-line MRZ, 36 characters wide.
        See Also:
        Constant Field Values
      • DOC_TYPE_ID3

        public static final int DOC_TYPE_ID3
        ID3 document type for passport booklets. Specifies a 2-line MRZ, 44 characters wide.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MRZInfo

        @Deprecated
        public MRZInfo​(String documentCode,
                       String issuingState,
                       String primaryIdentifier,
                       String secondaryIdentifier,
                       String documentNumber,
                       String nationality,
                       String dateOfBirth,
                       net.sf.scuba.data.Gender gender,
                       String dateOfExpiry,
                       String personalNumber)
        Creates a new 2-line MRZ compliant with ICAO Doc 9303 (pre-seventh edition) part 1 vol 1.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "P" or "V")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth
        gender - gender, must not be null
        dateOfExpiry - date of expiry
        personalNumber - either empty, or a personal number of maximum length 14, or other optional data of exact length 15
      • MRZInfo

        @Deprecated
        public MRZInfo​(String documentCode,
                       String issuingState,
                       String documentNumber,
                       String optionalData1,
                       String dateOfBirth,
                       net.sf.scuba.data.Gender gender,
                       String dateOfExpiry,
                       String nationality,
                       String optionalData2,
                       String primaryIdentifier,
                       String secondaryIdentifier)
        Creates a new 3-line MRZ compliant with ICAO Doc 9303 (pre-seventh edition) part 3 vol 1.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "I", "C", or "A")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth in YYMMDD format
        gender - gender, must not be null
        dateOfExpiry - date of expiry in YYMMDD format
        optionalData1 - optional data in line 1 of maximum length 15
        optionalData2 - optional data in line 2 of maximum length 11
      • MRZInfo

        public MRZInfo​(InputStream inputStream,
                       int length)
        Creates a new MRZ based on an input stream.
        Parameters:
        inputStream - contains the contents (value) of DG1 (without the tag and length)
        length - the length of the MRZInfo structure
      • MRZInfo

        public MRZInfo​(String str)
        Creates a new MRZ based on the text input. The text input may contain newlines, which will be ignored.
        Parameters:
        str - input text
    • Method Detail

      • createTD1MRZInfo

        public static MRZInfo createTD1MRZInfo​(String documentCode,
                                               String issuingState,
                                               String documentNumber,
                                               String optionalData1,
                                               String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               String dateOfExpiry,
                                               String nationality,
                                               String optionalData2,
                                               String primaryIdentifier,
                                               String secondaryIdentifier)
        Creates a new 3-line, 30 character (TD1) MRZ compliant with ICAO Doc 9303 (seventh edition) part 5.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "I", "C", or "A")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth in yyMMdd format
        gender - gender, must not be null
        dateOfExpiry - date of expiry in yyMMdd format
        optionalData1 - optional data in line 1 of maximum length 15
        optionalData2 - optional data in line 2 of maximum length 11
        Returns:
        the 3-line MRZ
      • createTD2MRZInfo

        public static MRZInfo createTD2MRZInfo​(String documentCode,
                                               String issuingState,
                                               String primaryIdentifier,
                                               String secondaryIdentifier,
                                               String documentNumber,
                                               String nationality,
                                               String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               String dateOfExpiry,
                                               String optionalData)
        Creates a new 2-line, 36 character (TD2) MRZ compliant with ICAO Doc 9303 (seventh edition) part 6.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "P" or "V")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth
        gender - gender, must not be null
        dateOfExpiry - date of expiry
        optionalData - either empty or optional data of maximal length 9
        Returns:
        the 2-line MRZ
      • createTD3MRZInfo

        public static MRZInfo createTD3MRZInfo​(String documentCode,
                                               String issuingState,
                                               String primaryIdentifier,
                                               String secondaryIdentifier,
                                               String documentNumber,
                                               String nationality,
                                               String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               String dateOfExpiry,
                                               String personalNumber)
        Creates a new 2-line, 44 character (TD3) MRZ compliant with ICAO Doc 9303 (seventh edition) part 4.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "P")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth
        gender - gender, must not be null
        dateOfExpiry - date of expiry
        personalNumber - either empty, or a personal number of maximum length 14, or other optional data of exact length 15
        Returns:
        the 2-line MRZ
      • createMRVAMRZInfo

        public static MRZInfo createMRVAMRZInfo​(String documentCode,
                                                String issuingState,
                                                String primaryIdentifier,
                                                String secondaryIdentifier,
                                                String documentNumber,
                                                String nationality,
                                                String dateOfBirth,
                                                net.sf.scuba.data.Gender gender,
                                                String dateOfExpiry,
                                                String optionalData)
        Creates a new 2-line, 44 character (MRV-A) MRZ compliant with ICAO Doc 9303 (seventh edition) part 7.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "V")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth
        gender - gender, must not be null
        dateOfExpiry - date of expiry
        optionalData - optional data at discretion of issuing state
        Returns:
        the 2-line MRZ
      • createMRVBMRZInfo

        public static MRZInfo createMRVBMRZInfo​(String documentCode,
                                                String issuingState,
                                                String primaryIdentifier,
                                                String secondaryIdentifier,
                                                String documentNumber,
                                                String nationality,
                                                String dateOfBirth,
                                                net.sf.scuba.data.Gender gender,
                                                String dateOfExpiry,
                                                String optionalData)
        Creates a new 2-line, 36 character (MRV-B) MRZ compliant with ICAO Doc 9303 (seventh edition) part 7.
        Parameters:
        documentCode - document code (1 or 2 digit, has to start with "V")
        issuingState - issuing state as 3 alpha string
        primaryIdentifier - card holder last name
        secondaryIdentifier - card holder first name(s)
        documentNumber - document number
        nationality - nationality as 3 alpha string
        dateOfBirth - date of birth
        gender - gender, must not be null
        dateOfExpiry - date of expiry
        optionalData - optional data at discretion of issuing state
        Returns:
        the 2-line MRZ
      • getDateOfBirth

        public String getDateOfBirth()
        Returns the date of birth of the passport holder.
        Returns:
        date of birth
      • getDateOfExpiry

        public String getDateOfExpiry()
        Returns the date of expiry.
        Returns:
        the date of expiry
      • getDocumentNumber

        public String getDocumentNumber()
        Returns the document number.
        Returns:
        document number
      • getDocumentType

        @Deprecated
        public int getDocumentType()
        Deprecated.
        Clients should determine type based on getDocumentCode()
        Returns the document type.
        Returns:
        document type
      • getDocumentCode

        public String getDocumentCode()
        Returns the document type.
        Returns:
        document type
      • getIssuingState

        public String getIssuingState()
        Returns the issuing state as a 3 letter code.
        Returns:
        the issuing state
      • getPrimaryIdentifier

        public String getPrimaryIdentifier()
        Returns the passport holder's last name.
        Returns:
        name
      • getSecondaryIdentifier

        public String getSecondaryIdentifier()
        Returns the document holder's first names.
        Returns:
        the secondary identifier
      • getSecondaryIdentifierComponents

        public String[] getSecondaryIdentifierComponents()
        Returns the document holder's first names.
        Returns:
        first names
      • getNationality

        public String getNationality()
        Returns the passport holder's nationality as a 3 digit code.
        Returns:
        a country
      • getPersonalNumber

        public String getPersonalNumber()
        Returns the personal number (if a personal number is encoded in optional data 1).
        Returns:
        personal number
      • getGender

        public net.sf.scuba.data.Gender getGender()
        Returns the passport holder's gender.
        Returns:
        gender
      • getOptionalData1

        public String getOptionalData1()
        Returns the contents of the first optional data field for ID-1 and ID-3 style MRZs.
        Returns:
        optional data 1
      • getOptionalData2

        public String getOptionalData2()
        Returns the contents of the second optional data field for ID-1 style MRZs.
        Returns:
        optional data 2
      • setDocumentCode

        @Deprecated
        public void setDocumentCode​(String documentCode)
        Deprecated.
        Class will become immutable
        Sets the document code.
        Parameters:
        documentCode - the new document code
      • setDocumentNumber

        @Deprecated
        public void setDocumentNumber​(String documentNumber)
        Deprecated.
        Class will become immutable
        Sets the document number.
        Parameters:
        documentNumber - new document number
      • setPrimaryIdentifier

        @Deprecated
        public void setPrimaryIdentifier​(String primaryIdentifier)
        Deprecated.
        Class will become immutable
        Sets the passport holder's last name.
        Parameters:
        primaryIdentifier - new primary identifier
      • setSecondaryIdentifierComponents

        @Deprecated
        public void setSecondaryIdentifierComponents​(String[] secondaryIdentifiers)
        Deprecated.
        Class will become immutable
        Sets the passport holder's first names.
        Parameters:
        secondaryIdentifiers - new secondary identifiers
      • setSecondaryIdentifiers

        @Deprecated
        public void setSecondaryIdentifiers​(String secondaryIdentifiers)
        Deprecated.
        Class will become immutable
        Sets the passport holder's first names.
        Parameters:
        secondaryIdentifiers - new secondary identifiers
      • setDateOfBirth

        @Deprecated
        public void setDateOfBirth​(String dateOfBirth)
        Deprecated.
        Class will become immutable
        Sets the date of birth.
        Parameters:
        dateOfBirth - new date of birth
      • setDateOfExpiry

        @Deprecated
        public void setDateOfExpiry​(String dateOfExpiry)
        Deprecated.
        Class will become immutable
        Sets the date of expiry.
        Parameters:
        dateOfExpiry - new date of expiry
      • setIssuingState

        @Deprecated
        public void setIssuingState​(String issuingState)
        Deprecated.
        Class will become immutable
        Sets the issuing state.
        Parameters:
        issuingState - new issuing state
      • setPersonalNumber

        @Deprecated
        public void setPersonalNumber​(String personalNumber)
        Deprecated.
        Class will become immutable
        Sets the personal number. Replacing any optional data 1.
        Parameters:
        personalNumber - new personal number
      • setNationality

        @Deprecated
        public void setNationality​(String nationality)
        Deprecated.
        Class will become immutable
        Sets the passport holder's nationality.
        Parameters:
        nationality - new nationality
      • setOptionalData2

        @Deprecated
        public void setOptionalData2​(String optionalData2)
        Deprecated.
        Class will become immutable
        Sets the contents for the second optional data field for ID-1 style MRZs.
        Parameters:
        optionalData2 - optional data 2
      • setGender

        @Deprecated
        public void setGender​(net.sf.scuba.data.Gender gender)
        Deprecated.
        Class will become immutable
        Sets the gender.
        Parameters:
        gender - new gender
      • toString

        public String toString()
        Creates a textual representation of this MRZ. This is the 2 or 3 line representation (depending on the document type) as it appears in the document. All lines end in a newline char.
        Overrides:
        toString in class Object
        Returns:
        the MRZ as text
        See Also:
        Object.toString()
      • hashCode

        public int hashCode()
        Returns the hash code for this MRZ info.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • equals

        public boolean equals​(Object obj)
        Whether this MRZ info is identical to some other object.
        Overrides:
        equals in class Object
        Parameters:
        obj - the other object
        Returns:
        a boolean
      • checkDigit

        public static char checkDigit​(String str)
        Computes the 7-3-1 check digit for part of the MRZ.
        Parameters:
        str - a part of the MRZ.
        Returns:
        the resulting check digit (in '0' - '9')
      • writeObject

        public void writeObject​(OutputStream outputStream)
                         throws IOException
        Writes the MRZ to an output stream. This just outputs the MRZ characters, and does not add newlines.
        Specified by:
        writeObject in class AbstractLDSInfo
        Parameters:
        outputStream - the output stream to write to
        Throws:
        IOException - on error writing to the stream
      • equalsModuloFillerChars

        public static boolean equalsModuloFillerChars​(String str1,
                                                      String str2)
        Tests equality of two MRZ string while ignoring extra filler characters.
        Parameters:
        str1 - an MRZ string
        str2 - another MRZ string
        Returns:
        a boolean indicating whether the strings are equal modulo filler characters