package t2;

import A2.v;
import F2.W;
import F2.X;
import F2.Y;
import F2.b0;
import F2.d0;
import F2.e0;
import F2.f0;
import F2.g0;
import F2.r0;
import com.google.crypto.tink.shaded.protobuf.AbstractC0472a;
import com.google.crypto.tink.shaded.protobuf.AbstractC0479h;
import com.google.crypto.tink.shaded.protobuf.AbstractC0492v;
import com.google.crypto.tink.shaded.protobuf.B;
import com.google.crypto.tink.shaded.protobuf.C0478g;
import com.google.crypto.tink.shaded.protobuf.C0482k;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public final class f {

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final f f9981d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final f f9982e;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f9983a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f9984b;

    static {
        int i = 0;
        f9980c = new f(i, "ENABLED");
        f9981d = new f(i, "DISABLED");
        f9982e = new f(i, "DESTROYED");
    }

    public /* synthetic */ f(int i, Object obj) {
        this.f9983a = i;
        this.f9984b = obj;
    }

    public synchronized void a(b0 b0Var) {
        f0 f0VarB;
        synchronized (this) {
            f0VarB = b(n.e(b0Var), b0Var.A());
        }
        d0 d0Var = (d0) this.f9984b;
        d0Var.e();
        g0.x((g0) d0Var.f5805l, f0VarB);
    }

    public synchronized f0 b(Y y5, r0 r0Var) {
        int iA;
        synchronized (this) {
            iA = v.a();
            while (d(iA)) {
                iA = v.a();
            }
        }
        return (f0) e0VarF.b();
        if (r0Var == r0.UNKNOWN_PREFIX) {
            throw new GeneralSecurityException("unknown output prefix type");
        }
        e0 e0VarF = f0.F();
        e0VarF.e();
        f0.w((f0) e0VarF.f5805l, y5);
        e0VarF.e();
        f0.z((f0) e0VarF.f5805l, iA);
        e0VarF.e();
        f0.y((f0) e0VarF.f5805l);
        e0VarF.e();
        f0.x((f0) e0VarF.f5805l, r0Var);
        return (f0) e0VarF.b();
    }

    public synchronized B2.a c() {
        return B2.a.o((g0) ((d0) this.f9984b).b());
    }

    public synchronized boolean d(int i) {
        Iterator it = Collections.unmodifiableList(((g0) ((d0) this.f9984b).f5805l).A()).iterator();
        while (it.hasNext()) {
            if (((f0) it.next()).B() == i) {
                return true;
            }
        }
        return false;
    }

    public Y e(AbstractC0479h abstractC0479h) throws GeneralSecurityException {
        A2.f fVar = (A2.f) this.f9984b;
        try {
            A2.e eVarD = fVar.d();
            AbstractC0472a abstractC0472aI = eVarD.i(abstractC0479h);
            eVarD.j(abstractC0472aI);
            AbstractC0472a abstractC0472aG = eVarD.g(abstractC0472aI);
            W wD = Y.D();
            String strB = fVar.b();
            wD.e();
            Y.w((Y) wD.f5805l, strB);
            try {
                int iB = ((AbstractC0492v) abstractC0472aG).b(null);
                byte[] bArr = new byte[iB];
                C0482k c0482k = new C0482k(iB, bArr);
                abstractC0472aG.f(c0482k);
                if (c0482k.f5779g - c0482k.f5780h != 0) {
                    throw new IllegalStateException("Did not write as much data as expected.");
                }
                C0478g c0478g = new C0478g(bArr);
                wD.e();
                Y.x((Y) wD.f5805l, c0478g);
                X xE = fVar.e();
                wD.e();
                Y.y((Y) wD.f5805l, xE);
                return (Y) wD.b();
            } catch (IOException e2) {
                throw new RuntimeException(abstractC0472aG.c("ByteString"), e2);
            }
        } catch (B e6) {
            throw new GeneralSecurityException("Unexpected proto", e6);
        }
    }

    public String toString() {
        switch (this.f9983a) {
            case 0:
                return (String) this.f9984b;
            default:
                return super.toString();
        }
    }

    public f(A2.f fVar, Class cls) {
        this.f9983a = 2;
        if (fVar.f31b.keySet().contains(cls) || Void.class.equals(cls)) {
            this.f9984b = fVar;
            return;
        }
        throw new IllegalArgumentException("Given internalKeyMananger " + fVar.toString() + " does not support primitive class " + cls.getName());
    }
}
