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

import android.content.Context;
import android.net.ConnectivityManager;
import com.mr.flutter.plugin.filepicker.FilePickerPlugin;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: loaded from: classes2.dex */
public final class o3 implements j6, c7, w8, ed.k {

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

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

    public /* synthetic */ o3(Object obj, int i10) {
        this.f21108a = i10;
        this.f21109b = obj;
    }

    @Override // com.google.android.gms.internal.pal.w8
    public m5 a(byte[] bArr) throws GeneralSecurityException {
        byte[] bArrN = q9.N();
        byte[] bArrZ = q9.z(bArrN, bArr);
        byte[] bArrX = q9.X(bArrN);
        byte[] bArrY = q9.Y(bArrX, bArr);
        byte[] bArrY2 = q9.Y(y8.f21379m, y8.f21368b);
        o3 o3Var = (o3) this.f21109b;
        int iD = o3Var.d();
        return new m5(o3Var.h(o3Var.i(q9.Y(y8.f21381o, bArrY2, "eae_prk".getBytes(StandardCharsets.UTF_8), bArrZ), null), iD, y8.c("shared_secret", bArrY, bArrY2, iD)), bArrX, 5);
    }

    @Override // ed.k
    public void b() {
        int i10 = this.f21108a;
        Object obj = this.f21109b;
        switch (i10) {
            case 0:
                ((FilePickerPlugin) obj).f24615b.f24639i = null;
                break;
            default:
                ((xyz.netfly.mobile.plugin.m) obj).f35088e = null;
                break;
        }
    }

    @Override // ed.k
    public void c(Object obj, ed.j jVar) {
        int i10 = this.f21108a;
        Object obj2 = this.f21109b;
        switch (i10) {
            case 0:
                ((FilePickerPlugin) obj2).f24615b.f24639i = jVar;
                break;
            default:
                ((xyz.netfly.mobile.plugin.m) obj2).f35088e = jVar;
                break;
        }
    }

    public int d() {
        switch (this.f21108a) {
            case 7:
                return Mac.getInstance((String) this.f21109b).getMacLength();
            default:
                return ((ke) this.f21109b).f21033a.length;
        }
    }

    public z0 e(zzaby zzabyVar) {
        z0 z0VarB = ((e9) this.f21109b).b(zzabyVar);
        ((e9) this.f21109b).d(z0VarB);
        return ((e9) this.f21109b).a(z0VarB);
    }

    public AtomicReference f(String str) {
        synchronized (this) {
            try {
                if (!((Map) this.f21109b).containsKey(str)) {
                    ((Map) this.f21109b).put(str, new AtomicReference());
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return (AtomicReference) ((Map) this.f21109b).get(str);
    }

    /* JADX WARN: Removed duplicated region for block: B:18:0x0038  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public byte[] g() throws GeneralSecurityException {
        byte b10;
        String str = (String) this.f21109b;
        int iHashCode = str.hashCode();
        if (iHashCode != 984523022) {
            if (iHashCode != 984524074) {
                b10 = (iHashCode == 984525777 && str.equals("HmacSha512")) ? (byte) 2 : (byte) -1;
            } else if (str.equals("HmacSha384")) {
                b10 = 1;
            }
        } else if (str.equals("HmacSha256")) {
            b10 = 0;
        }
        if (b10 == 0) {
            return y8.f21372f;
        }
        if (b10 == 1) {
            return y8.f21373g;
        }
        if (b10 == 2) {
            return y8.f21374h;
        }
        throw new GeneralSecurityException("Could not determine HPKE KDF ID");
    }

    public byte[] h(byte[] bArr, int i10, byte[] bArr2) throws GeneralSecurityException {
        Mac mac = (Mac) de.f20764f.a((String) this.f21109b);
        if (i10 > mac.getMacLength() * 255) {
            throw new GeneralSecurityException("size too large");
        }
        byte[] bArr3 = new byte[i10];
        mac.init(new SecretKeySpec(bArr, (String) this.f21109b));
        byte[] bArrDoFinal = new byte[0];
        int i11 = 1;
        int i12 = 0;
        while (true) {
            mac.update(bArrDoFinal);
            mac.update(bArr2);
            mac.update((byte) i11);
            bArrDoFinal = mac.doFinal();
            int length = bArrDoFinal.length;
            int i13 = i12 + length;
            if (i13 >= i10) {
                System.arraycopy(bArrDoFinal, 0, bArr3, i12, i10 - i12);
                return bArr3;
            }
            System.arraycopy(bArrDoFinal, 0, bArr3, i12, length);
            i11++;
            i12 = i13;
        }
    }

    public byte[] i(byte[] bArr, byte[] bArr2) throws InvalidKeyException {
        Mac mac = (Mac) de.f20764f.a((String) this.f21109b);
        if (bArr2 == null || bArr2.length == 0) {
            mac.init(new SecretKeySpec(new byte[mac.getMacLength()], (String) this.f21109b));
        } else {
            mac.init(new SecretKeySpec(bArr2, (String) this.f21109b));
        }
        return mac.doFinal(bArr);
    }

    @Override // com.google.android.gms.internal.pal.j6
    /* JADX INFO: renamed from: zza */
    public Object mo8zza() {
        switch (this.f21108a) {
            case 2:
                return ((k5) this.f21109b).d();
            default:
                Context context = (Context) this.f21109b;
                g5 g5Var = l5.f21036a;
                f5.f20904d.f20907c.e(context);
                return null;
        }
    }

    @Override // com.google.android.gms.internal.pal.w8
    public byte[] zzb() throws GeneralSecurityException {
        if (Arrays.equals(((o3) this.f21109b).g(), y8.f21372f)) {
            return y8.f21368b;
        }
        throw new GeneralSecurityException("Could not determine HPKE KEM ID");
    }

    public /* synthetic */ o3(int i10) {
        this.f21108a = i10;
        if (i10 != 9) {
            this.f21109b = new HashMap();
        } else {
            this.f21109b = new HashMap();
        }
    }

    public /* synthetic */ o3(ConnectivityManager connectivityManager) {
        this.f21108a = 0;
        if (connectivityManager != null) {
            try {
                connectivityManager.registerDefaultNetworkCallback(new m4.e(this, 7));
            } catch (RuntimeException unused) {
                synchronized (o3.class) {
                    this.f21109b = null;
                }
            }
        }
    }
}
