package org.jmrtd.lds.icao; import com.google.common.primitives.UnsignedBytes; import java.io.ByteArrayInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; import net.sf.scuba.tlv.TLVInputStream; import net.sf.scuba.tlv.TLVOutputStream; import o.C15109ghW; import o.ghS; import org.jmrtd.lds.DataGroup; /* loaded from: classes6.dex */ public class DG12File extends DataGroup { public static final int CONTENT_SPECIFIC_CONSTRUCTED_TAG = 160; public static final int COUNT_TAG = 2; public static final int DATE_AND_TIME_OF_PERSONALIZATION = 24405; public static final int DATE_OF_ISSUE_TAG = 24358; public static final int ENDORSEMENTS_AND_OBSERVATIONS_TAG = 24347; public static final int IMAGE_OF_FRONT_TAG = 24349; public static final int IMAGE_OF_REAR_TAG = 24350; public static final int ISSUING_AUTHORITY_TAG = 24345; public static final int NAME_OF_OTHER_PERSON_TAG = 24346; public static final int PERSONALIZATION_SYSTEM_SERIAL_NUMBER_TAG = 24406; private static final int TAG_LIST_TAG = 92; public static final int TAX_OR_EXIT_REQUIREMENTS_TAG = 24348; private static final long serialVersionUID = -1979367459379125674L; private Date dateAndTimeOfPersonalization; private Date dateOfIssue; private String endorsementsAndObservations; private byte[] imageOfFront; private byte[] imageOfRear; private String issuingAuthority; private List namesOfOtherPersons; private String personalizationSystemSerialNumber; private List tagPresenceList; private String taxOrExitRequirements; private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMdd"); private static final SimpleDateFormat SDTF = new SimpleDateFormat("yyyyMMddhhmmss"); private static final Logger LOGGER = Logger.getLogger("org.jmrtd"); @Override // org.jmrtd.lds.AbstractTaggedLDSFile public int getTag() { return 108; } public DG12File(String str, Date date, List list, String str2, String str3, byte[] bArr, byte[] bArr2, Date date2, String str4) { super(108); this.issuingAuthority = str; this.dateOfIssue = date; this.namesOfOtherPersons = list == null ? new ArrayList() : new ArrayList(list); this.endorsementsAndObservations = str2; this.taxOrExitRequirements = str3; this.imageOfFront = bArr; this.imageOfRear = bArr2; this.dateAndTimeOfPersonalization = date2; this.personalizationSystemSerialNumber = str4; } public DG12File(InputStream inputStream) throws IOException { super(108, inputStream); } @Override // org.jmrtd.lds.AbstractTaggedLDSFile public void readContent(InputStream inputStream) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); if (tLVInputStream.b() != 92) { throw new IllegalArgumentException("Expected tag list in DG12"); } int c = tLVInputStream.c(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tLVInputStream.d()); ArrayList arrayList = new ArrayList((c / 2) + 1); int i = 0; while (i < c) { int b = new TLVInputStream(byteArrayInputStream).b(); i += C15109ghW.b(b).length; arrayList.add(Integer.valueOf(b)); } Iterator it = arrayList.iterator(); while (it.hasNext()) { readField(((Integer) it.next()).intValue(), tLVInputStream); } } public List getTagPresenceList() { List list = this.tagPresenceList; if (list != null) { return list; } ArrayList arrayList = new ArrayList(10); this.tagPresenceList = arrayList; if (this.issuingAuthority != null) { arrayList.add(Integer.valueOf(ISSUING_AUTHORITY_TAG)); } if (this.dateOfIssue != null) { this.tagPresenceList.add(24358); } List list2 = this.namesOfOtherPersons; if (list2 != null && list2.size() > 0) { this.tagPresenceList.add(Integer.valueOf(NAME_OF_OTHER_PERSON_TAG)); } if (this.endorsementsAndObservations != null) { this.tagPresenceList.add(Integer.valueOf(ENDORSEMENTS_AND_OBSERVATIONS_TAG)); } if (this.taxOrExitRequirements != null) { this.tagPresenceList.add(Integer.valueOf(TAX_OR_EXIT_REQUIREMENTS_TAG)); } if (this.imageOfFront != null) { this.tagPresenceList.add(Integer.valueOf(IMAGE_OF_FRONT_TAG)); } if (this.imageOfRear != null) { this.tagPresenceList.add(Integer.valueOf(IMAGE_OF_REAR_TAG)); } if (this.dateAndTimeOfPersonalization != null) { this.tagPresenceList.add(Integer.valueOf(DATE_AND_TIME_OF_PERSONALIZATION)); } if (this.personalizationSystemSerialNumber != null) { this.tagPresenceList.add(Integer.valueOf(PERSONALIZATION_SYSTEM_SERIAL_NUMBER_TAG)); } return this.tagPresenceList; } private void readField(int i, TLVInputStream tLVInputStream) throws IOException { int b = tLVInputStream.b(); if (b == 160) { tLVInputStream.c(); int b2 = tLVInputStream.b(); if (b2 != 2) { StringBuilder sb = new StringBuilder("Expected "); sb.append(Integer.toHexString(2)); sb.append(", found "); sb.append(Integer.toHexString(b2)); throw new IllegalArgumentException(sb.toString()); } int c = tLVInputStream.c(); if (c != 1) { throw new IllegalArgumentException("Expected length 1 count length, found ".concat(String.valueOf(c))); } byte[] d = tLVInputStream.d(); if (d.length != 1) { StringBuilder sb2 = new StringBuilder("Number of content specific fields should be encoded in single byte, found "); sb2.append(Arrays.toString(d)); throw new IllegalArgumentException(sb2.toString()); } byte b3 = d[0]; for (int i2 = 0; i2 < (b3 & UnsignedBytes.MAX_VALUE); i2++) { int b4 = tLVInputStream.b(); if (b4 != 24346) { StringBuilder sb3 = new StringBuilder("Expected "); sb3.append(Integer.toHexString(NAME_OF_OTHER_PERSON_TAG)); sb3.append(", found "); sb3.append(Integer.toHexString(b4)); throw new IllegalArgumentException(sb3.toString()); } tLVInputStream.c(); parseNameOfOtherPerson(tLVInputStream.d()); } return; } if (b != i) { StringBuilder sb4 = new StringBuilder("Expected "); sb4.append(Integer.toHexString(i)); sb4.append(", but found "); sb4.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb4.toString()); } tLVInputStream.c(); byte[] d2 = tLVInputStream.d(); if (b == 24358) { parseDateOfIssue(d2); return; } if (b == 24405) { parseDateAndTimeOfPersonalization(d2); return; } if (b != 24406) { switch (b) { case ISSUING_AUTHORITY_TAG /* 24345 */: parseIssuingAuthority(d2); return; case NAME_OF_OTHER_PERSON_TAG /* 24346 */: parseNameOfOtherPerson(d2); return; case ENDORSEMENTS_AND_OBSERVATIONS_TAG /* 24347 */: parseEndorsementsAndObservations(d2); return; case TAX_OR_EXIT_REQUIREMENTS_TAG /* 24348 */: parseTaxOrExitRequirements(d2); return; case IMAGE_OF_FRONT_TAG /* 24349 */: parseImageOfFront(d2); return; case IMAGE_OF_REAR_TAG /* 24350 */: parseImageOfRear(d2); return; default: StringBuilder sb5 = new StringBuilder("Unknown field tag in DG12: "); sb5.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb5.toString()); } } parsePersonalizationSystemSerialNumber(d2); } private void parsePersonalizationSystemSerialNumber(byte[] bArr) { try { this.personalizationSystemSerialNumber = new String(bArr, "UTF-8").trim(); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); this.personalizationSystemSerialNumber = new String(bArr).trim(); } } private void parseDateAndTimeOfPersonalization(byte[] bArr) { try { this.dateAndTimeOfPersonalization = SDTF.parse(new String(bArr, "UTF-8").trim()); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); } catch (ParseException e2) { throw new IllegalArgumentException(e2.toString()); } } private void parseTaxOrExitRequirements(byte[] bArr) { try { this.taxOrExitRequirements = new String(bArr, "UTF-8").trim(); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); this.taxOrExitRequirements = new String(bArr).trim(); } } private void parseEndorsementsAndObservations(byte[] bArr) { try { this.endorsementsAndObservations = new String(bArr, "UTF-8").trim(); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); this.endorsementsAndObservations = new String(bArr).trim(); } } private void parseNameOfOtherPerson(byte[] bArr) { synchronized (this) { if (this.namesOfOtherPersons == null) { this.namesOfOtherPersons = new ArrayList(); } try { this.namesOfOtherPersons.add(new String(bArr, "UTF-8").trim()); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); this.namesOfOtherPersons.add(new String(bArr).trim()); } } } private void parseDateOfIssue(byte[] bArr) { if (bArr == null) { throw new IllegalArgumentException("Wrong date format"); } if (bArr.length == 8) { try { this.dateOfIssue = SDF.parse(new String(bArr, "UTF-8").trim()); return; } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); } catch (ParseException e2) { Logger logger2 = LOGGER; StringBuilder sb2 = new StringBuilder("Exception: "); sb2.append(e2.getMessage()); logger2.severe(sb2.toString()); } } LOGGER.warning("DG12 date of issue is not in expected ccyymmdd ASCII format"); if (bArr.length == 4) { try { this.dateOfIssue = SDF.parse(ghS.c(bArr).trim()); return; } catch (ParseException e3) { Logger logger3 = LOGGER; StringBuilder sb3 = new StringBuilder("Exception: "); sb3.append(e3.getMessage()); logger3.severe(sb3.toString()); } } throw new IllegalArgumentException("Wrong date format"); } private void parseIssuingAuthority(byte[] bArr) { try { this.issuingAuthority = new String(bArr, "UTF-8").trim(); } catch (UnsupportedEncodingException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); this.issuingAuthority = new String(bArr).trim(); } } @Override // org.jmrtd.lds.DataGroup, org.jmrtd.lds.AbstractTaggedLDSFile public String toString() { String obj; String obj2; StringBuffer stringBuffer = new StringBuffer("DG12File ["); String str = this.issuingAuthority; if (str == null) { str = ""; } stringBuffer.append(str); stringBuffer.append(", "); Date date = this.dateOfIssue; stringBuffer.append(date == null ? "" : SDF.format(date)); stringBuffer.append(", "); List list = this.namesOfOtherPersons; stringBuffer.append((list == null || list.size() == 0) ? "" : this.namesOfOtherPersons); stringBuffer.append(", "); String str2 = this.endorsementsAndObservations; if (str2 == null) { str2 = ""; } stringBuffer.append(str2); stringBuffer.append(", "); String str3 = this.taxOrExitRequirements; if (str3 == null) { str3 = ""; } stringBuffer.append(str3); stringBuffer.append(", "); if (this.imageOfFront == null) { obj = ""; } else { StringBuilder sb = new StringBuilder("image ("); sb.append(this.imageOfFront.length); sb.append(")"); obj = sb.toString(); } stringBuffer.append(obj); stringBuffer.append(", "); if (this.imageOfRear == null) { obj2 = ""; } else { StringBuilder sb2 = new StringBuilder("image ("); sb2.append(this.imageOfRear.length); sb2.append(")"); obj2 = sb2.toString(); } stringBuffer.append(obj2); stringBuffer.append(", "); Date date2 = this.dateAndTimeOfPersonalization; stringBuffer.append(date2 == null ? "" : SDF.format(date2)); stringBuffer.append(", "); String str4 = this.personalizationSystemSerialNumber; stringBuffer.append(str4 != null ? str4 : ""); stringBuffer.append("]"); return stringBuffer.toString(); } public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj.getClass().equals(getClass())) { return toString().equals(((DG12File) obj).toString()); } return false; } public int hashCode() { return (toString().hashCode() * 13) + 112; } @Override // org.jmrtd.lds.AbstractTaggedLDSFile public void writeContent(OutputStream outputStream) throws IOException { TLVOutputStream tLVOutputStream = outputStream instanceof TLVOutputStream ? (TLVOutputStream) outputStream : new TLVOutputStream(outputStream); tLVOutputStream.d(92); List tagPresenceList = getTagPresenceList(); DataOutputStream dataOutputStream = new DataOutputStream(tLVOutputStream); Iterator it = tagPresenceList.iterator(); while (it.hasNext()) { dataOutputStream.writeShort(it.next().intValue()); } dataOutputStream.flush(); tLVOutputStream.c(); Iterator it2 = tagPresenceList.iterator(); while (it2.hasNext()) { int intValue = it2.next().intValue(); if (intValue == 24358) { tLVOutputStream.d(intValue); tLVOutputStream.d(new String(SDF.format(this.dateOfIssue)).getBytes("UTF-8")); } else if (intValue == 24405) { tLVOutputStream.d(intValue); tLVOutputStream.d(new String(SDTF.format(this.dateAndTimeOfPersonalization)).getBytes("UTF-8")); } else if (intValue != 24406) { switch (intValue) { case ISSUING_AUTHORITY_TAG /* 24345 */: tLVOutputStream.d(intValue); tLVOutputStream.d(this.issuingAuthority.trim().getBytes("UTF-8")); break; case NAME_OF_OTHER_PERSON_TAG /* 24346 */: if (this.namesOfOtherPersons == null) { this.namesOfOtherPersons = new ArrayList(); } tLVOutputStream.d(160); tLVOutputStream.d(2); tLVOutputStream.write(this.namesOfOtherPersons.size()); tLVOutputStream.c(); for (String str : this.namesOfOtherPersons) { tLVOutputStream.d(NAME_OF_OTHER_PERSON_TAG); tLVOutputStream.d(str.trim().getBytes("UTF-8")); } tLVOutputStream.c(); break; case ENDORSEMENTS_AND_OBSERVATIONS_TAG /* 24347 */: tLVOutputStream.d(intValue); tLVOutputStream.d(this.endorsementsAndObservations.trim().getBytes("UTF-8")); break; case TAX_OR_EXIT_REQUIREMENTS_TAG /* 24348 */: tLVOutputStream.d(intValue); tLVOutputStream.d(this.taxOrExitRequirements.trim().getBytes("UTF-8")); break; case IMAGE_OF_FRONT_TAG /* 24349 */: tLVOutputStream.d(intValue); tLVOutputStream.d(this.imageOfFront); break; case IMAGE_OF_REAR_TAG /* 24350 */: tLVOutputStream.d(intValue); tLVOutputStream.d(this.imageOfRear); break; default: StringBuilder sb = new StringBuilder("Unknown field tag in DG12: "); sb.append(Integer.toHexString(intValue)); throw new IllegalArgumentException(sb.toString()); } } else { tLVOutputStream.d(intValue); tLVOutputStream.d(this.personalizationSystemSerialNumber.trim().getBytes("UTF-8")); } } } public String getTaxOrExitRequirements() { return this.taxOrExitRequirements; } public String getPersonalizationSystemSerialNumber() { return this.personalizationSystemSerialNumber; } public List getNamesOfOtherPersons() { return this.namesOfOtherPersons; } public String getIssuingAuthority() { return this.issuingAuthority; } public byte[] getImageOfRear() { return this.imageOfRear; } public byte[] getImageOfFront() { return this.imageOfFront; } public String getEndorsementsAndObservations() { return this.endorsementsAndObservations; } public Date getDateOfIssue() { return this.dateOfIssue; } public Date getDateAndTimeOfPersonalization() { return this.dateAndTimeOfPersonalization; } private void parseImageOfRear(byte[] bArr) { this.imageOfRear = bArr; } private void parseImageOfFront(byte[] bArr) { this.imageOfFront = bArr; } }