package fk;

import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.util.Iterator;
import mk.c0;
import mk.d0;
import mk.i0;
import mk.y;
import mk.z;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public abstract class s {

    /* renamed from: a, reason: collision with root package name */
    public static final Charset f18547a = Charset.forName("UTF-8");

    public static d0.c a(c0.c cVar) {
        return (d0.c) d0.c.L().w(cVar.K().L()).v(cVar.N()).u(cVar.M()).t(cVar.L()).i();
    }

    public static d0 b(c0 c0Var) {
        d0.b u10 = d0.L().u(c0Var.N());
        Iterator it = c0Var.M().iterator();
        while (it.hasNext()) {
            u10.t(a((c0.c) it.next()));
        }
        return (d0) u10.i();
    }

    public static void c(c0.c cVar) {
        if (!cVar.O()) {
            throw new GeneralSecurityException(String.format("key %d has no key data", Integer.valueOf(cVar.L())));
        }
        if (cVar.M() == i0.UNKNOWN_PREFIX) {
            throw new GeneralSecurityException(String.format("key %d has unknown prefix", Integer.valueOf(cVar.L())));
        }
        if (cVar.N() == z.UNKNOWN_STATUS) {
            throw new GeneralSecurityException(String.format("key %d has unknown status", Integer.valueOf(cVar.L())));
        }
    }

    public static void d(c0 c0Var) {
        int N = c0Var.N();
        int i10 = 0;
        boolean z10 = false;
        boolean z11 = true;
        for (c0.c cVar : c0Var.M()) {
            if (cVar.N() == z.ENABLED) {
                c(cVar);
                if (cVar.L() == N) {
                    if (z10) {
                        throw new GeneralSecurityException("keyset contains multiple primary keys");
                    }
                    z10 = true;
                }
                if (cVar.K().K() != y.c.ASYMMETRIC_PUBLIC) {
                    z11 = false;
                }
                i10++;
            }
        }
        if (i10 == 0) {
            throw new GeneralSecurityException("keyset must contain at least one ENABLED key");
        }
        if (!z10 && !z11) {
            throw new GeneralSecurityException("keyset doesn't contain a valid primary key");
        }
    }
}
