package ea;

import com.google.crypto.tink.proto.OutputPrefixType;
import com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException;
import java.security.GeneralSecurityException;
import ra.o1;
import ra.p1;
import ra.y0;

/* JADX INFO: loaded from: classes2.dex */
public abstract class o0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final ma.x f25717a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final ma.v f25718b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final ma.f f25719c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final ma.d f25720d;

    static {
        ta.a aVarC = ma.p0.c("type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey");
        f25717a = new ma.x(new c7.g(27), n0.class);
        f25718b = new ma.v(new c7.g(28), aVarC);
        f25719c = new ma.f(new c7.g(29), k0.class);
        f25720d = new ma.d(new androidx.core.view.n(0), aVarC);
    }

    public static n0 a(p1 p1Var, OutputPrefixType outputPrefixType) throws GeneralSecurityException {
        l0 l0Var;
        m0 m0Var;
        ra.x0 x0VarK = y0.K();
        x0VarK.j(p1Var.G().I());
        x0VarK.k(p1Var.G().J());
        x0VarK.i(OutputPrefixType.RAW);
        da.l lVarM = com.bumptech.glide.f.m(((y0) x0VarK.c()).e());
        boolean z10 = lVarM instanceof u;
        l0 l0Var2 = l0.f25695g;
        l0 l0Var3 = l0.f25694f;
        l0 l0Var4 = l0.f25693e;
        l0 l0Var5 = l0.f25691c;
        l0 l0Var6 = l0.f25692d;
        l0 l0Var7 = l0.f25690b;
        if (z10) {
            l0Var = l0Var7;
        } else if (lVarM instanceof c0) {
            l0Var = l0Var6;
        } else if (lVarM instanceof x0) {
            l0Var = l0Var5;
        } else if (lVarM instanceof m) {
            l0Var = l0Var4;
        } else if (lVarM instanceof q) {
            l0Var = l0Var3;
        } else {
            if (!(lVarM instanceof y)) {
                throw new GeneralSecurityException("Unsupported DEK parameters when parsing " + lVarM);
            }
            l0Var = l0Var2;
        }
        u.e eVar = new u.e(14);
        int iOrdinal = outputPrefixType.ordinal();
        m0 m0Var2 = m0.f25704c;
        if (iOrdinal == 1) {
            m0Var = m0.f25703b;
        } else {
            if (iOrdinal != 3) {
                throw new GeneralSecurityException("Unable to parse OutputPrefixType: " + outputPrefixType.b());
            }
            m0Var = m0Var2;
        }
        eVar.f33125a = m0Var;
        String strH = p1Var.H();
        eVar.f33126b = strH;
        c cVar = (c) lVarM;
        eVar.f33128d = cVar;
        eVar.f33127c = l0Var;
        if (((m0) eVar.f33125a) == null) {
            eVar.f33125a = m0Var2;
        }
        if (strH == null) {
            throw new GeneralSecurityException("kekUri must be set");
        }
        if (cVar == null) {
            throw new GeneralSecurityException("dekParametersForNewKeys must be set");
        }
        if (cVar.a()) {
            throw new GeneralSecurityException("dekParametersForNewKeys must not have ID Requirements");
        }
        l0 l0Var8 = (l0) eVar.f33127c;
        c cVar2 = (c) eVar.f33128d;
        if ((l0Var8.equals(l0Var7) && (cVar2 instanceof u)) || ((l0Var8.equals(l0Var6) && (cVar2 instanceof c0)) || ((l0Var8.equals(l0Var5) && (cVar2 instanceof x0)) || ((l0Var8.equals(l0Var4) && (cVar2 instanceof m)) || ((l0Var8.equals(l0Var3) && (cVar2 instanceof q)) || (l0Var8.equals(l0Var2) && (cVar2 instanceof y))))))) {
            return new n0((m0) eVar.f33125a, (String) eVar.f33126b, (l0) eVar.f33127c, (c) eVar.f33128d);
        }
        throw new GeneralSecurityException("Cannot use parsing strategy " + ((l0) eVar.f33127c).f25696a + " when new keys are picked according to " + ((c) eVar.f33128d) + ".");
    }

    public static p1 b(n0 n0Var) {
        try {
            y0 y0VarM = y0.M(com.bumptech.glide.f.q(n0Var.f25713d), com.google.crypto.tink.shaded.protobuf.q.a());
            o1 o1VarI = p1.I();
            String str = n0Var.f25711b;
            o1VarI.f();
            p1.D((p1) o1VarI.f23982b, str);
            o1VarI.f();
            p1.E((p1) o1VarI.f23982b, y0VarM);
            return (p1) o1VarI.c();
        } catch (InvalidProtocolBufferException e10) {
            throw new GeneralSecurityException("Parsing KmsEnvelopeAeadKeyFormat failed: ", e10);
        }
    }

    public static OutputPrefixType c(m0 m0Var) throws GeneralSecurityException {
        if (m0.f25703b.equals(m0Var)) {
            return OutputPrefixType.TINK;
        }
        if (m0.f25704c.equals(m0Var)) {
            return OutputPrefixType.RAW;
        }
        throw new GeneralSecurityException("Unable to serialize variant: " + m0Var);
    }
}
