package org.jmrtd.cbeff; import com.google.common.primitives.UnsignedBytes; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.security.AccessControlException; import java.util.HashMap; import java.util.logging.Logger; import net.sf.scuba.tlv.TLVInputStream; import o.C15109ghW; import org.bouncycastle.crypto.tls.CipherSuite; /* loaded from: classes6.dex */ public class ISO781611Decoder implements ISO781611 { private static final Logger LOGGER = Logger.getLogger("org.jmrtd"); private BiometricDataBlockDecoder bdbDecoder; public ISO781611Decoder(BiometricDataBlockDecoder biometricDataBlockDecoder) { this.bdbDecoder = biometricDataBlockDecoder; } public ComplexCBEFFInfo decode(InputStream inputStream) throws IOException { return readBITGroup(inputStream); } private ComplexCBEFFInfo readBITGroup(InputStream inputStream) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); int b = tLVInputStream.b(); if (b == 32609) { return readBITGroup(b, tLVInputStream.c(), inputStream); } StringBuilder sb = new StringBuilder("Expected tag "); sb.append(Integer.toHexString(32609)); sb.append(", found "); sb.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb.toString()); } private ComplexCBEFFInfo readBITGroup(int i, int i2, InputStream inputStream) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); ComplexCBEFFInfo complexCBEFFInfo = new ComplexCBEFFInfo(); if (i != 32609) { StringBuilder sb = new StringBuilder("Expected tag "); sb.append(Integer.toHexString(32609)); sb.append(", found "); sb.append(Integer.toHexString(i)); throw new IllegalArgumentException(sb.toString()); } int b = tLVInputStream.b(); if (b != 2) { StringBuilder sb2 = new StringBuilder("Expected tag BIOMETRIC_INFO_COUNT_TAG ("); sb2.append(Integer.toHexString(2)); sb2.append(") in CBEFF structure, found "); sb2.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb2.toString()); } int c = tLVInputStream.c(); if (c != 1) { throw new IllegalArgumentException("BIOMETRIC_INFO_COUNT should have length 1, found length ".concat(String.valueOf(c))); } byte[] d = tLVInputStream.d(); byte b2 = d[0]; for (int i3 = 0; i3 < (b2 & UnsignedBytes.MAX_VALUE); i3++) { complexCBEFFInfo.add(readBIT(inputStream, i3)); } return complexCBEFFInfo; } private CBEFFInfo readBIT(InputStream inputStream, int i) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); return readBIT(tLVInputStream.b(), tLVInputStream.c(), inputStream, i); } private CBEFFInfo readBIT(int i, int i2, InputStream inputStream, int i3) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); if (i != 32608) { StringBuilder sb = new StringBuilder("Expected tag BIOMETRIC_INFORMATION_TEMPLATE_TAG ("); sb.append(Integer.toHexString(32608)); sb.append("), found "); sb.append(Integer.toHexString(i)); sb.append(", index is "); sb.append(i3); throw new IllegalArgumentException(sb.toString()); } int b = tLVInputStream.b(); int c = tLVInputStream.c(); if (b == 125) { readStaticallyProtectedBIT(inputStream, b, c, i3); return null; } if ((b & 160) == 160) { return new SimpleCBEFFInfo(readBiometricDataBlock(inputStream, readBHT(inputStream, b, c, i3), i3)); } StringBuilder sb2 = new StringBuilder("Unsupported template tag: "); sb2.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb2.toString()); } private StandardBiometricHeader readBHT(InputStream inputStream, int i, int i2, int i3) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); if (i != 161) { StringBuilder sb = new StringBuilder("Expected tag "); sb.append(Integer.toHexString(CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384)); sb.append(", found "); sb.append(Integer.toHexString(i)); String obj = sb.toString(); Logger logger = LOGGER; if (logger != null) { logger.warning(obj); } } HashMap hashMap = new HashMap(); int i4 = 0; while (i4 < i2) { int b = tLVInputStream.b(); int length = C15109ghW.b(b).length; int length2 = C15109ghW.a(tLVInputStream.c()).length; byte[] d = tLVInputStream.d(); i4 = i4 + length + length2 + d.length; hashMap.put(Integer.valueOf(b), d); } return new StandardBiometricHeader(hashMap); } private void readStaticallyProtectedBIT(InputStream inputStream, int i, int i2, int i3) throws IOException { TLVInputStream tLVInputStream = new TLVInputStream(new ByteArrayInputStream(decodeSMTValue(inputStream))); readBiometricDataBlock(new ByteArrayInputStream(decodeSMTValue(inputStream)), readBHT(tLVInputStream, tLVInputStream.b(), tLVInputStream.c(), i3), i3); } private byte[] decodeSMTValue(InputStream inputStream) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); int b = tLVInputStream.b(); int c = tLVInputStream.c(); if (b == 129) { return tLVInputStream.d(); } if (b == 133) { throw new AccessControlException("Access denied. Biometric Information Template is statically protected."); } long j = 0; if (b == 142) { while (true) { long j2 = c; if (j >= j2) { return null; } j += tLVInputStream.skip(j2); } } else { if (b != 158) { return null; } while (true) { long j3 = c; if (j >= j3) { return null; } j += tLVInputStream.skip(j3); } } } /* JADX WARN: Type inference failed for: r5v1, types: [org.jmrtd.cbeff.BiometricDataBlock] */ private BiometricDataBlock readBiometricDataBlock(InputStream inputStream, StandardBiometricHeader standardBiometricHeader, int i) throws IOException { TLVInputStream tLVInputStream = inputStream instanceof TLVInputStream ? (TLVInputStream) inputStream : new TLVInputStream(inputStream); int b = tLVInputStream.b(); if (b != 24366 && b != 32558) { StringBuilder sb = new StringBuilder("Expected tag BIOMETRIC_DATA_BLOCK_TAG ("); sb.append(Integer.toHexString(24366)); sb.append(") or BIOMETRIC_DATA_BLOCK_TAG_ALT ("); sb.append(Integer.toHexString(32558)); sb.append("), found "); sb.append(Integer.toHexString(b)); throw new IllegalArgumentException(sb.toString()); } return this.bdbDecoder.decode(inputStream, standardBiometricHeader, i, tLVInputStream.c()); } }