package H3;

import A1.y;
import O3.v;
import T3.W;
import T3.X;
import T3.Y;
import T3.Z;
import T3.b0;
import T3.d0;
import T3.e0;
import T3.f0;
import T3.g0;
import T3.r0;
import com.google.crypto.tink.shaded.protobuf.AbstractC0735a;
import com.google.crypto.tink.shaded.protobuf.AbstractC0742h;
import com.google.crypto.tink.shaded.protobuf.AbstractC0755v;
import com.google.crypto.tink.shaded.protobuf.B;
import com.google.crypto.tink.shaded.protobuf.C0741g;
import com.google.crypto.tink.shaded.protobuf.C0745k;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import n4.u0;

/* 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 f3076c;

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

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

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

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

    static {
        int i = 0;
        f3076c = new f(i, "ENABLED");
        f3077d = new f(i, "DISABLED");
        f3078e = new f(i, "DESTROYED");
    }

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

    public synchronized void a(b0 b0Var) {
        f0 f0VarE = e(b0Var);
        d0 d0Var = (d0) this.f3080b;
        d0Var.h();
        g0.x((g0) d0Var.f10543r, f0VarE);
    }

    public synchronized f0 b(Y y8, r0 r0Var) {
        e0 e0VarF;
        int iG = g();
        if (r0Var == r0.f6586r) {
            throw new GeneralSecurityException("unknown output prefix type");
        }
        e0VarF = f0.F();
        e0VarF.h();
        f0.w((f0) e0VarF.f10543r, y8);
        e0VarF.h();
        f0.z((f0) e0VarF.f10543r, iG);
        e0VarF.h();
        f0.y((f0) e0VarF.f10543r);
        e0VarF.h();
        f0.x((f0) e0VarF.f10543r, r0Var);
        return (f0) e0VarF.d();
    }

    public synchronized y c() {
        return y.q((g0) ((d0) this.f3080b).d());
    }

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

    public synchronized f0 e(b0 b0Var) {
        return b(n.d(b0Var), b0Var.A());
    }

    public Y f(AbstractC0742h abstractC0742h) throws GeneralSecurityException {
        O3.f fVar = (O3.f) this.f3080b;
        try {
            O3.e eVarF = fVar.f();
            AbstractC0735a abstractC0735aV = eVarF.v(abstractC0742h);
            eVarF.D(abstractC0735aV);
            AbstractC0735a abstractC0735aI = eVarF.i(abstractC0735aV);
            W wD = Y.D();
            String strC = fVar.c();
            wD.h();
            Y.w((Y) wD.f10543r, strC);
            try {
                int iA = ((AbstractC0755v) abstractC0735aI).a(null);
                byte[] bArr = new byte[iA];
                C0745k c0745k = new C0745k(iA, bArr);
                abstractC0735aI.f(c0745k);
                if (c0745k.f10517j - c0745k.f10518k != 0) {
                    throw new IllegalStateException("Did not write as much data as expected.");
                }
                C0741g c0741g = new C0741g(bArr);
                wD.h();
                Y.x((Y) wD.f10543r, c0741g);
                X xG = fVar.g();
                wD.h();
                Y.y((Y) wD.f10543r, xG);
                return (Y) wD.d();
            } catch (IOException e8) {
                throw new RuntimeException(abstractC0735aI.b("ByteString"), e8);
            }
        } catch (B e9) {
            throw new GeneralSecurityException("Unexpected proto", e9);
        }
    }

    public synchronized int g() {
        int iA;
        iA = v.a();
        while (d(iA)) {
            iA = v.a();
        }
        return iA;
    }

    public synchronized void h(int i) {
        for (int i5 = 0; i5 < ((g0) ((d0) this.f3080b).f10543r).z(); i5++) {
            try {
                f0 f0VarY = ((g0) ((d0) this.f3080b).f10543r).y(i5);
                if (f0VarY.B() == i) {
                    if (!f0VarY.D().equals(Z.f6580s)) {
                        throw new GeneralSecurityException("cannot set key as primary because it's not enabled: " + i);
                    }
                    d0 d0Var = (d0) this.f3080b;
                    d0Var.h();
                    g0.w((g0) d0Var.f10543r, i);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        throw new GeneralSecurityException("key not found: " + i);
    }

    public String toString() {
        switch (this.f3079a) {
            case u0.f15495q /* 0 */:
                return (String) this.f3080b;
            default:
                return super.toString();
        }
    }

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