package o; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import o.C15293gmh; import o.glX; import org.ejbca.cvc.CVCAuthorizationTemplate; import org.ejbca.cvc.CVCertificate; import org.ejbca.cvc.exception.ConstructionException; import org.ejbca.cvc.exception.ParseException; /* loaded from: classes6.dex */ public final class glV { public static AbstractC15245glT e(byte[] bArr, glS gls) throws ParseException, ConstructionException { ByteArrayInputStream byteArrayInputStream; try { try { byteArrayInputStream = new ByteArrayInputStream(bArr); try { AbstractC15245glT a = a(new DataInputStream(byteArrayInputStream), gls); byteArrayInputStream.close(); return a; } catch (Throwable th) { th = th; if (byteArrayInputStream != null) { byteArrayInputStream.close(); } throw th; } } catch (Throwable th2) { th = th2; byteArrayInputStream = null; } } catch (IOException e) { throw new ParseException(e); } } private static AbstractC15245glT a(DataInputStream dataInputStream, glS gls) throws IOException, ConstructionException, ParseException { glS gls2; glA cVCertificate; int readUnsignedByte = dataInputStream.readUnsignedByte(); if ((readUnsignedByte & 31) == 31) { readUnsignedByte = (readUnsignedByte << 8) + dataInputStream.readByte(); } glS[] values = glS.values(); int length = values.length; int i = 0; while (true) { if (i >= length) { gls2 = null; break; } gls2 = values[i]; if (gls2.value == readUnsignedByte) { break; } i++; } if (gls2 == null) { StringBuilder sb = new StringBuilder("Unknown CVC tag value "); sb.append(Integer.toHexString(readUnsignedByte)); throw new ParseException(sb.toString()); } if (gls != null && gls2 != gls) { StringBuilder sb2 = new StringBuilder("Expected first tag "); sb2.append(gls); sb2.append(" but found "); sb2.append(gls2); throw new ParseException(sb2.toString()); } int d = AbstractC15245glT.d(dataInputStream); if (gls2.isSequence) { int available = dataInputStream.available(); if (!gls2.isSequence) { StringBuilder sb3 = new StringBuilder("Tag "); sb3.append(gls2); sb3.append(" is not a sequence"); throw new IllegalArgumentException(sb3.toString()); } int i2 = C15293gmh.AnonymousClass1.e[gls2.ordinal()]; if (i2 == 1) { cVCertificate = new CVCertificate(); } else if (i2 == 2) { cVCertificate = new glQ(); } else if (i2 == 3) { cVCertificate = new glY(); } else if (i2 == 4) { cVCertificate = new CVCAuthorizationTemplate(); } else if (i2 == 5) { cVCertificate = new glM(); } else { throw new IllegalArgumentException("Unsupported type ".concat(String.valueOf(gls2))); } while (dataInputStream.available() > available - d) { cVCertificate.c(a(dataInputStream, null)); } return cVCertificate instanceof glY ? C15290gme.d((glY) cVCertificate) : cVCertificate; } byte[] bArr = new byte[d]; dataInputStream.read(bArr, 0, d); if (gls2.isSequence) { StringBuilder sb4 = new StringBuilder("Tag "); sb4.append(gls2); sb4.append(" is a sequence"); throw new IllegalArgumentException(sb4.toString()); } switch (glX.AnonymousClass3.e[gls2.ordinal()]) { case 1: return new glZ(gls2, bArr); case 2: return new glZ(gls2, bArr); case 3: return new glL(bArr); case 4: return new glW(bArr); case 5: return new C15288gmc(bArr); case 6: return new glF(bArr); case 7: return new C15287gmb(gls2, bArr); case 8: return new C15287gmb(gls2, bArr); default: return new glK(gls2, bArr); } } }