Class MRZInfo

  • All Implemented Interfaces:
    java.io.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: 1870 $
    Author:
    The JMRTD team ([email protected])
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DOC_TYPE_ID1
      ID1 document type for credit card sized identity cards.
      static int DOC_TYPE_ID2
      ID2 document type.
      static int DOC_TYPE_ID3
      ID3 document type for passport booklets.
      static int DOC_TYPE_UNSPECIFIED
      Unspecified document type (do not use, choose ID1 or ID3).
    • Constructor Summary

      Constructors 
      Constructor Description
      MRZInfo​(java.io.InputStream inputStream, int length)
      Creates a new MRZ based on an input stream.
      MRZInfo​(java.lang.String str)
      Creates a new MRZ based on the text input.
      MRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier, java.lang.String documentNumber, java.lang.String nationality, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String personalNumber)
      MRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String documentNumber, java.lang.String optionalData1, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String nationality, java.lang.String optionalData2, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static char checkDigit​(java.lang.String str)
      Computes the 7-3-1 check digit for part of the MRZ.
      static MRZInfo createMRVAMRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier, java.lang.String documentNumber, java.lang.String nationality, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String optionalData)
      Creates a new 2-line, 44 character (MRV-A) MRZ compliant with ICAO Doc 9303 (seventh edition) part 7.
      static MRZInfo createMRVBMRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier, java.lang.String documentNumber, java.lang.String nationality, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String optionalData)
      Creates a new 2-line, 36 character (MRV-B) MRZ compliant with ICAO Doc 9303 (seventh edition) part 7.
      static MRZInfo createTD1MRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String documentNumber, java.lang.String optionalData1, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String nationality, java.lang.String optionalData2, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier)
      Creates a new 3-line, 30 character (TD1) MRZ compliant with ICAO Doc 9303 (seventh edition) part 5.
      static MRZInfo createTD2MRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier, java.lang.String documentNumber, java.lang.String nationality, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String optionalData)
      Creates a new 2-line, 36 character (TD2) MRZ compliant with ICAO Doc 9303 (seventh edition) part 6.
      static MRZInfo createTD3MRZInfo​(java.lang.String documentCode, java.lang.String issuingState, java.lang.String primaryIdentifier, java.lang.String secondaryIdentifier, java.lang.String documentNumber, java.lang.String nationality, java.lang.String dateOfBirth, net.sf.scuba.data.Gender gender, java.lang.String dateOfExpiry, java.lang.String personalNumber)
      Creates a new 2-line, 44 character (TD3) MRZ compliant with ICAO Doc 9303 (seventh edition) part 4.
      boolean equals​(java.lang.Object obj)
      Whether this MRZ info is identical to some other object.
      static boolean equalsModuloFillerChars​(java.lang.String str1, java.lang.String str2)
      Tests equality of two MRZ string while ignoring extra filler characters.
      java.lang.String getDateOfBirth()
      Returns the date of birth of the passport holder.
      java.lang.String getDateOfExpiry()
      Returns the date of expiry.
      java.lang.String getDocumentCode()
      Returns the document type.
      java.lang.String getDocumentNumber()
      Returns the document number.
      int getDocumentType()
      Deprecated.
      Clients should determine type based on getDocumentCode()
      net.sf.scuba.data.Gender getGender()
      Returns the passport holder's gender.
      java.lang.String getIssuingState()
      Returns the issuing state as a 3 letter code.
      java.lang.String getNationality()
      Returns the passport holder's nationality as a 3 digit code.
      java.lang.String getOptionalData1()
      Returns the contents of the first optional data field for ID-1 and ID-3 style MRZs.
      java.lang.String getOptionalData2()
      Returns the contents of the second optional data field for ID-1 style MRZs.
      java.lang.String getPersonalNumber()
      Returns the personal number (if a personal number is encoded in optional data 1).
      java.lang.String getPrimaryIdentifier()
      Returns the passport holder's last name.
      java.lang.String getSecondaryIdentifier()
      Returns the document holder's first names.
      java.lang.String[] getSecondaryIdentifierComponents()
      Returns the document holder's first names.
      int hashCode()
      Returns the hash code for this MRZ info.
      void setDateOfBirth​(java.lang.String dateOfBirth)
      Deprecated.
      Class will become immutable
      void setDateOfExpiry​(java.lang.String dateOfExpiry)
      Deprecated.
      Class will become immutable
      void setDocumentCode​(java.lang.String documentCode)
      Deprecated.
      Class will become immutable
      void setDocumentNumber​(java.lang.String documentNumber)
      Deprecated.
      Class will become immutable
      void setGender​(net.sf.scuba.data.Gender gender)
      Deprecated.
      Class will become immutable
      void setIssuingState​(java.lang.String issuingState)
      Deprecated.
      Class will become immutable
      void setNationality​(java.lang.String nationality)
      Deprecated.
      Class will become immutable
      void setOptionalData2​(java.lang.String optionalData2)
      Deprecated.
      Class will become immutable
      void setPersonalNumber​(java.lang.String personalNumber)
      Deprecated.
      Class will become immutable
      void setPrimaryIdentifier​(java.lang.String primaryIdentifier)
      Deprecated.
      Class will become immutable
      void setSecondaryIdentifierComponents​(java.lang.String[] secondaryIdentifiers)
      Deprecated.
      Class will become immutable
      void setSecondaryIdentifiers​(java.lang.String secondaryIdentifiers)
      Deprecated.
      Class will become immutable
      java.lang.String toString()
      Creates a textual representation of this MRZ.
      void writeObject​(java.io.OutputStream outputStream)
      Writes the MRZ to an output stream.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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​(java.lang.String documentCode,
                       java.lang.String issuingState,
                       java.lang.String primaryIdentifier,
                       java.lang.String secondaryIdentifier,
                       java.lang.String documentNumber,
                       java.lang.String nationality,
                       java.lang.String dateOfBirth,
                       net.sf.scuba.data.Gender gender,
                       java.lang.String dateOfExpiry,
                       java.lang.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​(java.lang.String documentCode,
                       java.lang.String issuingState,
                       java.lang.String documentNumber,
                       java.lang.String optionalData1,
                       java.lang.String dateOfBirth,
                       net.sf.scuba.data.Gender gender,
                       java.lang.String dateOfExpiry,
                       java.lang.String nationality,
                       java.lang.String optionalData2,
                       java.lang.String primaryIdentifier,
                       java.lang.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​(java.io.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​(java.lang.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​(java.lang.String documentCode,
                                               java.lang.String issuingState,
                                               java.lang.String documentNumber,
                                               java.lang.String optionalData1,
                                               java.lang.String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               java.lang.String dateOfExpiry,
                                               java.lang.String nationality,
                                               java.lang.String optionalData2,
                                               java.lang.String primaryIdentifier,
                                               java.lang.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​(java.lang.String documentCode,
                                               java.lang.String issuingState,
                                               java.lang.String primaryIdentifier,
                                               java.lang.String secondaryIdentifier,
                                               java.lang.String documentNumber,
                                               java.lang.String nationality,
                                               java.lang.String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               java.lang.String dateOfExpiry,
                                               java.lang.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​(java.lang.String documentCode,
                                               java.lang.String issuingState,
                                               java.lang.String primaryIdentifier,
                                               java.lang.String secondaryIdentifier,
                                               java.lang.String documentNumber,
                                               java.lang.String nationality,
                                               java.lang.String dateOfBirth,
                                               net.sf.scuba.data.Gender gender,
                                               java.lang.String dateOfExpiry,
                                               java.lang.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​(java.lang.String documentCode,
                                                java.lang.String issuingState,
                                                java.lang.String primaryIdentifier,
                                                java.lang.String secondaryIdentifier,
                                                java.lang.String documentNumber,
                                                java.lang.String nationality,
                                                java.lang.String dateOfBirth,
                                                net.sf.scuba.data.Gender gender,
                                                java.lang.String dateOfExpiry,
                                                java.lang.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​(java.lang.String documentCode,
                                                java.lang.String issuingState,
                                                java.lang.String primaryIdentifier,
                                                java.lang.String secondaryIdentifier,
                                                java.lang.String documentNumber,
                                                java.lang.String nationality,
                                                java.lang.String dateOfBirth,
                                                net.sf.scuba.data.Gender gender,
                                                java.lang.String dateOfExpiry,
                                                java.lang.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 java.lang.String getDateOfBirth()
        Returns the date of birth of the passport holder.
        Returns:
        date of birth
      • getDateOfExpiry

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

        public java.lang.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 java.lang.String getDocumentCode()
        Returns the document type.
        Returns:
        document type
      • getIssuingState

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

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

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

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

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

        public java.lang.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 java.lang.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 java.lang.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​(java.lang.String documentCode)
        Deprecated.
        Class will become immutable
        Sets the document code.
        Parameters:
        documentCode - the new document code
      • setDocumentNumber

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

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

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

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

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

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

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

        @Deprecated
        public void setPersonalNumber​(java.lang.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​(java.lang.String nationality)
        Deprecated.
        Class will become immutable
        Sets the passport holder's nationality.
        Parameters:
        nationality - new nationality
      • setOptionalData2

        @Deprecated
        public void setOptionalData2​(java.lang.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 java.lang.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 java.lang.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 java.lang.Object
        Returns:
        the hash code
      • equals

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

        public static char checkDigit​(java.lang.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​(java.io.OutputStream outputStream)
                         throws java.io.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:
        java.io.IOException - on error writing to the stream
      • equalsModuloFillerChars

        public static boolean equalsModuloFillerChars​(java.lang.String str1,
                                                      java.lang.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