what-the-bank/sources/org/jmrtd/lds/icao/COMFile.java

273 lines
11 KiB
Java

package org.jmrtd.lds.icao;
import com.google.common.primitives.UnsignedBytes;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IllegalFormatConversionException;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import net.sf.scuba.tlv.TLVInputStream;
import net.sf.scuba.tlv.TLVOutputStream;
import org.jmrtd.lds.AbstractTaggedLDSFile;
import org.jmrtd.lds.LDSFileUtil;
/* loaded from: classes6.dex */
public class COMFile extends AbstractTaggedLDSFile {
private static final int TAG_LIST_TAG = 92;
private static final int VERSION_LDS_TAG = 24321;
private static final int VERSION_UNICODE_TAG = 24374;
private static final long serialVersionUID = 2002455279067170063L;
private String majorVersionUnicode;
private String minorVersionUnicode;
private String releaseLevelUnicode;
private List<Integer> tagList;
private String updateLevelLDS;
private String versionLDS;
public COMFile(String str, String str2, String str3, String str4, String str5, int[] iArr) {
super(96);
initialize(str, str2, str3, str4, str5, iArr);
}
public COMFile(String str, String str2, int[] iArr) {
super(96);
try {
if (str == null) {
throw new IllegalArgumentException("Null versionLDS");
}
if (str2 == null) {
throw new IllegalArgumentException("Null versionUnicode");
}
StringTokenizer stringTokenizer = new StringTokenizer(str, ".");
if (stringTokenizer.countTokens() != 2) {
throw new IllegalArgumentException("Could not parse LDS version. Expecting 2 level version number x.y.");
}
int parseInt = Integer.parseInt(stringTokenizer.nextToken().trim());
int parseInt2 = Integer.parseInt(stringTokenizer.nextToken().trim());
StringTokenizer stringTokenizer2 = new StringTokenizer(str2, ".");
if (stringTokenizer2.countTokens() != 3) {
throw new IllegalArgumentException("Could not parse unicode version. Expecting 3 level version number x.y.z.");
}
initialize(String.format("%02d", Integer.valueOf(parseInt)), String.format("%02d", Integer.valueOf(parseInt2)), String.format("%02d", Integer.valueOf(Integer.parseInt(stringTokenizer2.nextToken().trim()))), String.format("%02d", Integer.valueOf(Integer.parseInt(stringTokenizer2.nextToken().trim()))), String.format("%02d", Integer.valueOf(Integer.parseInt(stringTokenizer2.nextToken().trim()))), iArr);
} catch (NumberFormatException e) {
StringBuilder sb = new StringBuilder("Could not parse version number. ");
sb.append(e.getMessage());
throw new IllegalArgumentException(sb.toString());
} catch (IllegalFormatConversionException e2) {
StringBuilder sb2 = new StringBuilder("Could not parse version number. ");
sb2.append(e2.getMessage());
throw new IllegalArgumentException(sb2.toString());
}
}
private void initialize(String str, String str2, String str3, String str4, String str5, int[] iArr) {
if (iArr == null) {
throw new IllegalArgumentException("Null tag list");
}
if (str == null || str.length() != 2 || str2 == null || str2.length() != 2 || str3 == null || str3.length() != 2 || str4 == null || str4.length() != 2 || str5 == null || str5.length() != 2 || iArr == null) {
throw new IllegalArgumentException();
}
this.versionLDS = str;
this.updateLevelLDS = str2;
this.majorVersionUnicode = str3;
this.minorVersionUnicode = str4;
this.releaseLevelUnicode = str5;
this.tagList = new ArrayList(iArr.length);
for (int i : iArr) {
this.tagList.add(Integer.valueOf(i));
}
}
public COMFile(InputStream inputStream) throws IOException {
super(96, inputStream);
}
@Override // org.jmrtd.lds.AbstractTaggedLDSFile
public void readContent(InputStream inputStream) throws IOException {
TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream);
int b = tLVInputStream.b();
if (b != VERSION_LDS_TAG) {
StringBuilder sb = new StringBuilder("Excepected VERSION_LDS_TAG (");
sb.append(Integer.toHexString(VERSION_LDS_TAG));
sb.append("), found ");
sb.append(Integer.toHexString(b));
throw new IllegalArgumentException(sb.toString());
}
if (tLVInputStream.c() != 4) {
throw new IllegalArgumentException("Wrong length of LDS version object");
}
byte[] d = tLVInputStream.d();
this.versionLDS = new String(d, 0, 2);
this.updateLevelLDS = new String(d, 2, 2);
int b2 = tLVInputStream.b();
if (b2 != 24374) {
StringBuilder sb2 = new StringBuilder("Expected VERSION_UNICODE_TAG (");
sb2.append(Integer.toHexString(24374));
sb2.append("), found ");
sb2.append(Integer.toHexString(b2));
throw new IllegalArgumentException(sb2.toString());
}
if (tLVInputStream.c() != 6) {
throw new IllegalArgumentException("Wrong length of LDS version object");
}
byte[] d2 = tLVInputStream.d();
this.majorVersionUnicode = new String(d2, 0, 2);
this.minorVersionUnicode = new String(d2, 2, 2);
this.releaseLevelUnicode = new String(d2, 4, 2);
int b3 = tLVInputStream.b();
if (b3 != 92) {
StringBuilder sb3 = new StringBuilder("Expected TAG_LIST_TAG (");
sb3.append(Integer.toHexString(92));
sb3.append("), found ");
sb3.append(Integer.toHexString(b3));
throw new IllegalArgumentException(sb3.toString());
}
tLVInputStream.c();
byte[] d3 = tLVInputStream.d();
this.tagList = new ArrayList();
for (byte b4 : d3) {
this.tagList.add(Integer.valueOf(b4 & UnsignedBytes.MAX_VALUE));
}
}
public String getLDSVersion() {
StringBuilder sb = new StringBuilder();
sb.append(this.versionLDS);
sb.append(".");
sb.append(this.updateLevelLDS);
String obj = sb.toString();
try {
int parseInt = Integer.parseInt(this.versionLDS);
int parseInt2 = Integer.parseInt(this.updateLevelLDS);
StringBuilder sb2 = new StringBuilder();
sb2.append(parseInt);
sb2.append(".");
sb2.append(parseInt2);
return sb2.toString();
} catch (NumberFormatException unused) {
return obj;
}
}
public String getUnicodeVersion() {
StringBuilder sb = new StringBuilder();
sb.append(this.majorVersionUnicode);
sb.append(".");
sb.append(this.minorVersionUnicode);
sb.append(".");
sb.append(this.releaseLevelUnicode);
String obj = sb.toString();
try {
int parseInt = Integer.parseInt(this.majorVersionUnicode);
int parseInt2 = Integer.parseInt(this.minorVersionUnicode);
int parseInt3 = Integer.parseInt(this.releaseLevelUnicode);
StringBuilder sb2 = new StringBuilder();
sb2.append(parseInt);
sb2.append(".");
sb2.append(parseInt2);
sb2.append(".");
sb2.append(parseInt3);
return sb2.toString();
} catch (NumberFormatException unused) {
return obj;
}
}
public int[] getTagList() {
int[] iArr = new int[this.tagList.size()];
Iterator<Integer> it = this.tagList.iterator();
int i = 0;
while (it.hasNext()) {
iArr[i] = it.next().intValue();
i++;
}
return iArr;
}
public void insertTag(Integer num) {
if (this.tagList.contains(num)) {
return;
}
this.tagList.add(num);
Collections.sort(this.tagList);
}
@Override // org.jmrtd.lds.AbstractTaggedLDSFile
public void writeContent(OutputStream outputStream) throws IOException {
TLVOutputStream tLVOutputStream = outputStream instanceof TLVOutputStream ? (TLVOutputStream) outputStream : new TLVOutputStream(outputStream);
tLVOutputStream.d(VERSION_LDS_TAG);
StringBuilder sb = new StringBuilder();
sb.append(this.versionLDS);
sb.append(this.updateLevelLDS);
tLVOutputStream.d(sb.toString().getBytes());
tLVOutputStream.d(24374);
StringBuilder sb2 = new StringBuilder();
sb2.append(this.majorVersionUnicode);
sb2.append(this.minorVersionUnicode);
sb2.append(this.releaseLevelUnicode);
tLVOutputStream.d(sb2.toString().getBytes());
tLVOutputStream.d(92);
tLVOutputStream.a(this.tagList.size());
Iterator<Integer> it = this.tagList.iterator();
while (it.hasNext()) {
tLVOutputStream.write((byte) it.next().intValue());
}
}
@Override // org.jmrtd.lds.AbstractTaggedLDSFile
public String toString() {
StringBuffer stringBuffer = new StringBuffer("COMFile ");
StringBuilder sb = new StringBuilder("LDS ");
sb.append(this.versionLDS);
sb.append(".");
sb.append(this.updateLevelLDS);
stringBuffer.append(sb.toString());
stringBuffer.append(", ");
StringBuilder sb2 = new StringBuilder("Unicode ");
sb2.append(this.majorVersionUnicode);
sb2.append(".");
sb2.append(this.minorVersionUnicode);
sb2.append(".");
sb2.append(this.releaseLevelUnicode);
stringBuffer.append(sb2.toString());
stringBuffer.append(", [");
int size = this.tagList.size();
Iterator<Integer> it = this.tagList.iterator();
int i = 0;
while (it.hasNext()) {
int intValue = it.next().intValue();
StringBuilder sb3 = new StringBuilder("DG");
sb3.append(LDSFileUtil.lookupDataGroupNumberByTag(intValue));
stringBuffer.append(sb3.toString());
if (i < size - 1) {
stringBuffer.append(", ");
}
i++;
}
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 false;
}
COMFile cOMFile = (COMFile) obj;
return this.versionLDS.equals(cOMFile.versionLDS) && this.updateLevelLDS.equals(cOMFile.updateLevelLDS) && this.majorVersionUnicode.equals(cOMFile.majorVersionUnicode) && this.minorVersionUnicode.equals(cOMFile.minorVersionUnicode) && this.releaseLevelUnicode.equals(cOMFile.releaseLevelUnicode) && this.tagList.equals(cOMFile.tagList);
}
public int hashCode() {
return (this.versionLDS.hashCode() * 3) + (this.updateLevelLDS.hashCode() * 5) + (this.majorVersionUnicode.hashCode() * 7) + (this.minorVersionUnicode.hashCode() * 11) + (this.releaseLevelUnicode.hashCode() * 13) + (this.tagList.hashCode() * 17);
}
}