package org.jmrtd.cbeff; import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; import java.util.List; import java.util.Map; import net.sf.scuba.tlv.TLVOutputStream; import org.bouncycastle.crypto.tls.CipherSuite; import org.jmrtd.cbeff.BiometricDataBlock; /* loaded from: classes6.dex */ public class ISO781611Encoder implements ISO781611 { private BiometricDataBlockEncoder bdbEncoder; public ISO781611Encoder(BiometricDataBlockEncoder biometricDataBlockEncoder) { this.bdbEncoder = biometricDataBlockEncoder; } public void encode(CBEFFInfo cBEFFInfo, OutputStream outputStream) throws IOException { if (cBEFFInfo instanceof SimpleCBEFFInfo) { writeBITGroup(Arrays.asList(cBEFFInfo), outputStream); } else if (cBEFFInfo instanceof ComplexCBEFFInfo) { writeBITGroup(((ComplexCBEFFInfo) cBEFFInfo).getSubRecords(), outputStream); } } private void writeBITGroup(List list, OutputStream outputStream) throws IOException { TLVOutputStream tLVOutputStream = outputStream instanceof TLVOutputStream ? (TLVOutputStream) outputStream : new TLVOutputStream(outputStream); tLVOutputStream.d(32609); tLVOutputStream.d(2); int size = list.size(); tLVOutputStream.d(new byte[]{(byte) size}); for (int i = 0; i < size; i++) { writeBIT(tLVOutputStream, i, (SimpleCBEFFInfo) list.get(i)); } tLVOutputStream.c(); } private void writeBIT(TLVOutputStream tLVOutputStream, int i, SimpleCBEFFInfo simpleCBEFFInfo) throws IOException { if (!(simpleCBEFFInfo instanceof SimpleCBEFFInfo)) { throw new IllegalArgumentException("Encoder does not support level > 2 nesting"); } tLVOutputStream.d(32608); writeBHT(tLVOutputStream, i, simpleCBEFFInfo); writeBiometricDataBlock(tLVOutputStream, simpleCBEFFInfo.getBiometricDataBlock()); tLVOutputStream.c(); } private void writeBHT(TLVOutputStream tLVOutputStream, int i, SimpleCBEFFInfo simpleCBEFFInfo) throws IOException { tLVOutputStream.d(CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384); for (Map.Entry entry : simpleCBEFFInfo.getBiometricDataBlock().getStandardBiometricHeader().getElements().entrySet()) { tLVOutputStream.d(entry.getKey().intValue()); tLVOutputStream.d(entry.getValue()); } tLVOutputStream.c(); } private void writeBiometricDataBlock(TLVOutputStream tLVOutputStream, B b) throws IOException { tLVOutputStream.d(24366); this.bdbEncoder.encode(b, tLVOutputStream); tLVOutputStream.c(); } }