package ma;

import com.google.crypto.tink.config.internal.TinkFipsUtil$AlgorithmFipsCompatibility;
import java.security.GeneralSecurityException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes2.dex */
public final class c {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Logger f30499c = Logger.getLogger(c.class.getName());

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public ConcurrentHashMap f30501a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ConcurrentHashMap f30502b;

    static {
        c cVar = new c();
        cVar.f30501a = new ConcurrentHashMap();
        cVar.f30502b = new ConcurrentHashMap();
        f30500d = cVar;
    }

    public final h a(Class cls, String str) throws GeneralSecurityException {
        h hVarB = b(str);
        if (hVarB.f30518b.equals(cls)) {
            return hVarB;
        }
        throw new GeneralSecurityException("Primitive type " + cls.getName() + " not supported by key manager of type " + h.class + ", which only supports: " + hVarB.f30518b);
    }

    public final synchronized h b(String str) {
        if (!this.f30501a.containsKey(str)) {
            throw new GeneralSecurityException("No key manager found for key type " + str + ", see https://developers.google.com/tink/faq/registration_errors");
        }
        return (h) this.f30501a.get(str);
    }

    public final synchronized void c(h hVar) {
        try {
            String str = hVar.f30517a;
            if (this.f30502b.containsKey(str) && !((Boolean) this.f30502b.get(str)).booleanValue()) {
                throw new GeneralSecurityException("New keys are already disallowed for key type " + str);
            }
            if (((h) this.f30501a.get(str)) != null && !h.class.equals(h.class)) {
                f30499c.warning("Attempted overwrite of a registered key manager for key type " + str);
                throw new GeneralSecurityException(String.format("typeUrl (%s) is already registered with %s, cannot be re-registered with %s", str, h.class.getName(), h.class.getName()));
            }
            this.f30501a.putIfAbsent(str, hVar);
            this.f30502b.put(str, Boolean.TRUE);
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void d(h hVar) {
        e(hVar, TinkFipsUtil$AlgorithmFipsCompatibility.f23814a);
    }

    public final synchronized void e(h hVar, TinkFipsUtil$AlgorithmFipsCompatibility tinkFipsUtil$AlgorithmFipsCompatibility) {
        if (!tinkFipsUtil$AlgorithmFipsCompatibility.a()) {
            throw new GeneralSecurityException("Cannot register key manager: FIPS compatibility insufficient");
        }
        c(hVar);
    }
}
