package com.google.android.gms.internal.pal;

import java.security.GeneralSecurityException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

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

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

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

    public j7() {
        this.f20996a = new ConcurrentHashMap();
    }

    public final m5 a(Class cls, String str) {
        i7 i7VarD = d(str);
        if (i7VarD.zze().contains(cls)) {
            return i7VarD.zza(cls);
        }
        String name = cls.getName();
        String strValueOf = String.valueOf(i7VarD.zzc());
        Set<Class> setZze = i7VarD.zze();
        StringBuilder sb = new StringBuilder();
        boolean z10 = true;
        for (Class cls2 : setZze) {
            if (!z10) {
                sb.append(", ");
            }
            sb.append(cls2.getCanonicalName());
            z10 = false;
        }
        String string = sb.toString();
        StringBuilder sbT = defpackage.e.t("Primitive type ", name, " not supported by key manager of type ", strValueOf, ", supported primitives: ");
        sbT.append(string);
        throw new GeneralSecurityException(sbT.toString());
    }

    public final synchronized void b(o9 o9Var, b8 b8Var) {
        Class clsZzd;
        try {
            int iH = b8Var.h();
            int i10 = 1;
            if (!q9.y(1)) {
                throw new GeneralSecurityException("failed to register key manager " + String.valueOf(o9Var.getClass()) + " as it is not FIPS compatible.");
            }
            if (!q9.y(iH)) {
                throw new GeneralSecurityException("failed to register key manager " + String.valueOf(b8.class) + " as it is not FIPS compatible.");
            }
            String strE = o9Var.e();
            String strE2 = b8Var.e();
            if (this.f20996a.containsKey(strE) && ((i7) this.f20996a.get(strE)).zzd() != null && (clsZzd = ((i7) this.f20996a.get(strE)).zzd()) != null && !clsZzd.getName().equals(b8.class.getName())) {
                f20995b.logp(Level.WARNING, "com.google.crypto.tink.KeyManagerRegistry", "registerAsymmetricKeyManagers", "Attempted overwrite of a registered key manager for key type " + strE + " with inconsistent public key type " + strE2);
                throw new GeneralSecurityException(String.format("public key manager corresponding to %s is already registered with %s, cannot be re-registered with %s", o9Var.getClass().getName(), clsZzd.getName(), b8.class.getName()));
            }
            e(new h7(o9Var, b8Var), true);
            e(new g7(b8Var, i10), false);
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void c(b8 b8Var) {
        if (!q9.y(b8Var.h())) {
            throw new GeneralSecurityException("failed to register key manager " + String.valueOf(b8.class) + " as it is not FIPS compatible.");
        }
        e(new g7(b8Var, 1), false);
    }

    public final synchronized i7 d(String str) {
        if (!this.f20996a.containsKey(str)) {
            throw new GeneralSecurityException("No key manager found for key type ".concat(String.valueOf(str)));
        }
        return (i7) this.f20996a.get(str);
    }

    public final synchronized void e(i7 i7Var, boolean z10) {
        try {
            String strE = ((k.e) i7Var.zzb().f21081b).e();
            i7 i7Var2 = (i7) this.f20996a.get(strE);
            if (i7Var2 != null && !i7Var2.zzc().equals(i7Var.zzc())) {
                f20995b.logp(Level.WARNING, "com.google.crypto.tink.KeyManagerRegistry", "registerKeyManagerContainer", "Attempted overwrite of a registered key manager for key type ".concat(strE));
                throw new GeneralSecurityException(String.format("typeUrl (%s) is already registered with %s, cannot be re-registered with %s", strE, i7Var2.zzc().getName(), i7Var.zzc().getName()));
            }
            if (z10) {
                this.f20996a.put(strE, i7Var);
            } else {
                this.f20996a.putIfAbsent(strE, i7Var);
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public j7(j7 j7Var) {
        this.f20996a = new ConcurrentHashMap(j7Var.f20996a);
    }
}
