Package org.jmrtd.lds.icao
Class MRZInfo
- java.lang.Object
-
- org.jmrtd.lds.AbstractLDSInfo
-
- org.jmrtd.lds.icao.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 part 1 and 3.- Version:
- $Revision: 1799 $
- 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(InputStream inputStream, int length)
Creates a new MRZ based on an input stream.MRZInfo(String str)
Creates a new MRZ based on the text input.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 part 1 vol 1.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 part 3 vol 1.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static char
checkDigit(String str)
Computes the 7-3-1 check digit for part of the MRZ.boolean
equals(Object obj)
Whether this MRZ info is identical to some other object.static boolean
equalsModuloFillerChars(String str1, String str2)
Tests equality of two MRZ string while ignoring extra filler characters.String
getDateOfBirth()
Gets the date of birth of the passport holder.String
getDateOfExpiry()
Returns the date of expiry.String
getDocumentCode()
Returns the document type.String
getDocumentNumber()
Gets the document number.int
getDocumentType()
Gets the document type.net.sf.scuba.data.Gender
getGender()
Gets the passport holder's gender.String
getIssuingState()
Returns the issuing state as a 3 letter code.String
getNationality()
Gets the passport holder's nationality as a 3 digit code.String
getOptionalData1()
Gets the contents of the first optional data field for ID-1 and ID-3 style MRZs.String
getOptionalData2()
Gets the contents of the second optional data field for ID-1 style MRZs.String
getPersonalNumber()
Returns the personal number (if a personal number is encoded in optional data 1).String
getPrimaryIdentifier()
Gets the passport holder's last name.String
getSecondaryIdentifier()
Gets the document holder's first names.String[]
getSecondaryIdentifierComponents()
Gets the document holder's first names.int
hashCode()
Gets a hash code for this MRZ info.void
setDateOfBirth(String dateOfBirth)
Sets the date of birth.void
setDateOfExpiry(String dateOfExpiry)
Sets the date of expiry.void
setDocumentCode(String documentCode)
Sets the document code.void
setDocumentNumber(String documentNumber)
Sets the document number.void
setGender(net.sf.scuba.data.Gender gender)
Sets the gender.void
setIssuingState(String issuingState)
Sets the issuing state.void
setNationality(String nationality)
Sets the passport holder's nationality.void
setOptionalData2(String optionalData2)
Sets the contents for the second optional data field for ID-1 style MRZs.void
setPersonalNumber(String personalNumber)
Sets the personal number.void
setPrimaryIdentifier(String primaryIdentifier)
Sets the passport holder's last name.void
setSecondaryIdentifierComponents(String[] secondaryIdentifiers)
Sets the passport holder's first names.void
setSecondaryIdentifiers(String secondaryIdentifiers)
Sets the passport holder's first names.String
toString()
Creates a textual representation of this MRZ.void
writeObject(OutputStream outputStream)
Writes the MRZ to an output stream.-
Methods inherited from class org.jmrtd.lds.AbstractLDSInfo
getEncoded
-
-
-
-
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
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 part 1 vol 1.- Parameters:
documentCode
- document code (1 or 2 digit, has to start with "P" or "V")issuingState
- issuing state as 3 digit stringprimaryIdentifier
- card holder last namesecondaryIdentifier
- card holder first name(s)documentNumber
- document numbernationality
- nationality as 3 digit stringdateOfBirth
- date of birthgender
- genderdateOfExpiry
- date of expirypersonalNumber
- either empty, or a personal number of maximum length 14, or other optional data of exact length 15
-
MRZInfo
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 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 digit stringprimaryIdentifier
- card holder last namesecondaryIdentifier
- card holder first name(s)documentNumber
- document numbernationality
- nationality as 3 digit stringdateOfBirth
- date of birth in YYMMDD formatgender
- genderdateOfExpiry
- date of expiry in YYMMDD formatoptionalData1
- optional data in line 1 of maximum length 15optionalData2
- 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
-
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 classAbstractLDSInfo
- Parameters:
outputStream
- the output stream to write to- Throws:
IOException
- on error writing to the stream
-
getDateOfBirth
public String getDateOfBirth()
Gets the date of birth of the passport holder.- Returns:
- date of birth
-
setDateOfBirth
public void setDateOfBirth(String dateOfBirth)
Sets the date of birth.- Parameters:
dateOfBirth
- new date of birth
-
getDateOfExpiry
public String getDateOfExpiry()
Returns the date of expiry.- Returns:
- the date of expiry
-
setDateOfExpiry
public void setDateOfExpiry(String dateOfExpiry)
Sets the date of expiry.- Parameters:
dateOfExpiry
- new date of expiry
-
getDocumentNumber
public String getDocumentNumber()
Gets the document number.- Returns:
- document number
-
setDocumentNumber
public void setDocumentNumber(String documentNumber)
Sets the document number.- Parameters:
documentNumber
- new document number
-
getDocumentType
public int getDocumentType()
Gets the document type.- Returns:
- document type
-
getDocumentCode
public String getDocumentCode()
Returns the document type.- Returns:
- document type
-
setDocumentCode
public void setDocumentCode(String documentCode)
Sets the document code.- Parameters:
documentCode
- the new document code
-
getIssuingState
public String getIssuingState()
Returns the issuing state as a 3 letter code.- Returns:
- the issuing state
-
setIssuingState
public void setIssuingState(String issuingState)
Sets the issuing state.- Parameters:
issuingState
- new issuing state
-
getPrimaryIdentifier
public String getPrimaryIdentifier()
Gets the passport holder's last name.- Returns:
- name
-
setPrimaryIdentifier
public void setPrimaryIdentifier(String primaryIdentifier)
Sets the passport holder's last name.- Parameters:
primaryIdentifier
- new primary identifier
-
getSecondaryIdentifier
public String getSecondaryIdentifier()
Gets the document holder's first names.- Returns:
- the secondary identifier
-
getSecondaryIdentifierComponents
public String[] getSecondaryIdentifierComponents()
Gets the document holder's first names.- Returns:
- first names
-
setSecondaryIdentifierComponents
public void setSecondaryIdentifierComponents(String[] secondaryIdentifiers)
Sets the passport holder's first names.- Parameters:
secondaryIdentifiers
- new secondary identifiers
-
setSecondaryIdentifiers
public void setSecondaryIdentifiers(String secondaryIdentifiers)
Sets the passport holder's first names.- Parameters:
secondaryIdentifiers
- new secondary identifiers
-
getNationality
public String getNationality()
Gets the passport holder's nationality as a 3 digit code.- Returns:
- a country
-
setNationality
public void setNationality(String nationality)
Sets the passport holder's nationality.- Parameters:
nationality
- new nationality
-
getPersonalNumber
public String getPersonalNumber()
Returns the personal number (if a personal number is encoded in optional data 1).- Returns:
- personal number
-
setPersonalNumber
public void setPersonalNumber(String personalNumber)
Sets the personal number.- Parameters:
personalNumber
- new personal number
-
getOptionalData1
public String getOptionalData1()
Gets the contents of the first optional data field for ID-1 and ID-3 style MRZs.- Returns:
- optional data 1
-
getOptionalData2
public String getOptionalData2()
Gets the contents of the second optional data field for ID-1 style MRZs.- Returns:
- optional data 2
-
setOptionalData2
public void setOptionalData2(String optionalData2)
Sets the contents for the second optional data field for ID-1 style MRZs.- Parameters:
optionalData2
- optional data 2
-
getGender
public net.sf.scuba.data.Gender getGender()
Gets the passport holder's gender.- Returns:
- gender
-
setGender
public void setGender(net.sf.scuba.data.Gender gender)
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 classObject
- Returns:
- the MRZ as text
- See Also:
Object.toString()
-
hashCode
public int hashCode()
Gets a hash code for this MRZ info.
-
equals
public boolean equals(Object obj)
Whether this MRZ info is identical to some other object.
-
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')
-
equalsModuloFillerChars
public static boolean equalsModuloFillerChars(String str1, String str2)
Tests equality of two MRZ string while ignoring extra filler characters.- Parameters:
str1
- an MRZ stringstr2
- another MRZ string- Returns:
- a boolean indicating whether the strings are equal modulo filler characters
-
-