package L3;

import F.I;
import S3.t;
import X3.W;
import X3.X;
import X3.Y;
import X3.b0;
import X3.d0;
import X3.e0;
import X3.f0;
import X3.g0;
import X3.r0;
import com.google.crypto.tink.shaded.protobuf.AbstractC1253a;
import com.google.crypto.tink.shaded.protobuf.AbstractC1261i;
import com.google.crypto.tink.shaded.protobuf.AbstractC1274w;
import com.google.crypto.tink.shaded.protobuf.C;
import com.google.crypto.tink.shaded.protobuf.C1260h;
import com.google.crypto.tink.shaded.protobuf.C1264l;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.Iterator;
import q.AbstractC2761L;

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

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

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

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

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

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

    static {
        int i6 = 0;
        f4169c = new f("ENABLED", i6);
        f4170d = new f("DISABLED", i6);
        f4171e = new f("DESTROYED", i6);
    }

    public /* synthetic */ f(Object obj, int i6) {
        this.f4172a = i6;
        this.f4173b = obj;
    }

    public synchronized void a(b0 b0Var) {
        f0 f0VarB;
        synchronized (this) {
            f0VarB = b(n.e(b0Var), b0Var.z());
        }
        d0 d0Var = (d0) this.f4173b;
        d0Var.d();
        g0.w((g0) d0Var.f13838b, f0VarB);
    }

    public synchronized f0 b(Y y6, r0 r0Var) {
        int iA;
        synchronized (this) {
            iA = t.a();
            while (d(iA)) {
                iA = t.a();
            }
        }
        return (f0) e0VarE.a();
        if (r0Var == r0.UNKNOWN_PREFIX) {
            throw new GeneralSecurityException("unknown output prefix type");
        }
        e0 e0VarE = f0.E();
        e0VarE.d();
        f0.v((f0) e0VarE.f13838b, y6);
        e0VarE.d();
        f0.y((f0) e0VarE.f13838b, iA);
        e0VarE.d();
        f0.x((f0) e0VarE.f13838b);
        e0VarE.d();
        f0.w((f0) e0VarE.f13838b, r0Var);
        return (f0) e0VarE.a();
    }

    public synchronized C4.f c() {
        return C4.f.s((g0) ((d0) this.f4173b).a());
    }

    public synchronized boolean d(int i6) {
        Iterator it = Collections.unmodifiableList(((g0) ((d0) this.f4173b).f13838b).z()).iterator();
        while (it.hasNext()) {
            if (((f0) it.next()).A() == i6) {
                return true;
            }
        }
        return false;
    }

    public Y e(AbstractC1261i abstractC1261i) throws GeneralSecurityException {
        S3.d dVar = (S3.d) this.f4173b;
        try {
            I iD = dVar.d();
            AbstractC1253a abstractC1253aH = iD.h(abstractC1261i);
            iD.m(abstractC1253aH);
            AbstractC1253a abstractC1253aA = iD.a(abstractC1253aH);
            W wC = Y.C();
            String strB = dVar.b();
            wC.d();
            Y.v((Y) wC.f13838b, strB);
            try {
                int iA = ((AbstractC1274w) abstractC1253aA).a(null);
                byte[] bArr = new byte[iA];
                C1264l c1264l = new C1264l(bArr, iA);
                abstractC1253aA.e(c1264l);
                if (c1264l.f13811j - c1264l.f13812k != 0) {
                    throw new IllegalStateException("Did not write as much data as expected.");
                }
                C1260h c1260h = new C1260h(bArr);
                wC.d();
                Y.w((Y) wC.f13838b, c1260h);
                X xE = dVar.e();
                wC.d();
                Y.x((Y) wC.f13838b, xE);
                return (Y) wC.a();
            } catch (IOException e6) {
                throw new RuntimeException(abstractC1253aA.b("ByteString"), e6);
            }
        } catch (C e7) {
            throw new GeneralSecurityException("Unexpected proto", e7);
        }
    }

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

    public f(S3.d dVar, Class cls) {
        this.f4172a = 2;
        if (!dVar.f6224b.keySet().contains(cls) && !Void.class.equals(cls)) {
            throw new IllegalArgumentException(AbstractC2761L.g("Given internalKeyMananger ", dVar.toString(), " does not support primitive class ", cls.getName()));
        }
        this.f4173b = dVar;
    }
}
