package md;

import androidx.fragment.app.k;
import androidx.lifecycle.f0;
import androidx.lifecycle.g0;
import dn.l;
import java.util.Arrays;
import java.util.concurrent.Executor;
import javax.crypto.Cipher;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import ld.m;
import rm.i;
import rm.n0;
import s.f;

/* loaded from: classes4.dex */
public final class c implements f {

    /* renamed from: a, reason: collision with root package name */
    private final t7.c f29031a;

    /* renamed from: b, reason: collision with root package name */
    private final ja.d f29032b;

    /* renamed from: c, reason: collision with root package name */
    private final e f29033c;

    /* renamed from: d, reason: collision with root package name */
    private final f0 f29034d;

    /* loaded from: classes4.dex */
    static final class a extends v implements l {
        a() {
            super(1);
        }

        public final void a(Boolean bool) {
            if (!bool.booleanValue()) {
                c.this.clear();
            }
            ja.d dVar = c.this.f29032b;
            t.d(bool);
            dVar.putBoolean("USE_BIOMETRIC", bool.booleanValue());
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Boolean) obj);
            return n0.f34904a;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public static final class b {

        /* renamed from: a, reason: collision with root package name */
        private final byte[] f29036a;

        /* renamed from: b, reason: collision with root package name */
        private final byte[] f29037b;

        public b(byte[] ciphertext, byte[] iv) {
            t.g(ciphertext, "ciphertext");
            t.g(iv, "iv");
            this.f29036a = ciphertext;
            this.f29037b = iv;
        }

        public final byte[] a() {
            return this.f29036a;
        }

        public final byte[] b() {
            return this.f29037b;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof b)) {
                return false;
            }
            b bVar = (b) obj;
            return t.b(this.f29036a, bVar.f29036a) && t.b(this.f29037b, bVar.f29037b);
        }

        public int hashCode() {
            return (Arrays.hashCode(this.f29036a) * 31) + Arrays.hashCode(this.f29037b);
        }

        public String toString() {
            return "CiphertextWrapper(ciphertext=" + Arrays.toString(this.f29036a) + ", iv=" + Arrays.toString(this.f29037b) + ")";
        }
    }

    /* renamed from: md.c$c, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    private static final class C0659c {

        /* renamed from: a, reason: collision with root package name */
        private final String f29038a;

        /* renamed from: b, reason: collision with root package name */
        private final String f29039b;

        public C0659c(String userName, String password) {
            t.g(userName, "userName");
            t.g(password, "password");
            this.f29038a = userName;
            this.f29039b = password;
        }

        public final String a() {
            return this.f29039b;
        }

        public final String b() {
            return this.f29038a;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof C0659c)) {
                return false;
            }
            C0659c c0659c = (C0659c) obj;
            return t.b(this.f29038a, c0659c.f29038a) && t.b(this.f29039b, c0659c.f29039b);
        }

        public int hashCode() {
            return (this.f29038a.hashCode() * 31) + this.f29039b.hashCode();
        }

        public String toString() {
            return "Credentials(userName=" + this.f29038a + ", password=" + this.f29039b + ")";
        }
    }

    /* loaded from: classes4.dex */
    static final class d implements g0, n {

        /* renamed from: a, reason: collision with root package name */
        private final /* synthetic */ l f29040a;

        d(l function) {
            t.g(function, "function");
            this.f29040a = function;
        }

        @Override // kotlin.jvm.internal.n
        public final i b() {
            return this.f29040a;
        }

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f29040a.invoke(obj);
        }

        public final boolean equals(Object obj) {
            if ((obj instanceof g0) && (obj instanceof n)) {
                return t.b(b(), ((n) obj).b());
            }
            return false;
        }

        public final int hashCode() {
            return b().hashCode();
        }
    }

    public c(t7.c contextService, ja.d sharedPreferencesService, e biometricCryptography) {
        t.g(contextService, "contextService");
        t.g(sharedPreferencesService, "sharedPreferencesService");
        t.g(biometricCryptography, "biometricCryptography");
        this.f29031a = contextService;
        this.f29032b = sharedPreferencesService;
        this.f29033c = biometricCryptography;
        f0 f0Var = new f0();
        f0Var.q(Boolean.valueOf(sharedPreferencesService.getBoolean("USE_BIOMETRIC", false)));
        this.f29034d = f0Var;
        f().k(new d(new a()));
    }

    private final f.d i(boolean z10) {
        f.d.a aVar = new f.d.a();
        aVar.f(this.f29031a.getString(m.f27984h));
        aVar.d(this.f29031a.getString(m.f27982g));
        aVar.e(this.f29031a.getString(m.f27994m));
        aVar.c(false);
        aVar.b(15);
        f.d a10 = aVar.a();
        t.f(a10, "build(...)");
        return a10;
    }

    private final b j() {
        String string = this.f29032b.getString("BIOMETRIC_DATA", null);
        if (string != null) {
            return (b) new com.google.gson.d().j(string, b.class);
        }
        return null;
    }

    private final void k(b bVar) {
        this.f29032b.putString("BIOMETRIC_DATA", bVar != null ? new com.google.gson.d().u(bVar) : null);
    }

    @Override // md.f
    public rm.v a(Cipher cipher) {
        byte[] bArr;
        t.g(cipher, "cipher");
        b j10 = j();
        if (j10 == null || (bArr = j10.a()) == null) {
            bArr = new byte[0];
        }
        C0659c c0659c = (C0659c) new com.google.gson.d().j(this.f29033c.c(bArr, cipher), C0659c.class);
        return new rm.v(c0659c.b(), c0659c.a());
    }

    @Override // md.f
    public boolean b() {
        return e() && t.b(f().f(), Boolean.TRUE);
    }

    @Override // md.f
    public void c(k activity, boolean z10, f.a callback) {
        byte[] bArr;
        Cipher e10;
        t.g(activity, "activity");
        t.g(callback, "callback");
        if (!(z10 ? b() : g())) {
            clear();
            callback.a(13, "");
            return;
        }
        try {
            if (z10) {
                e10 = this.f29033c.b("BIOMETRIC_KEY_NAME");
            } else {
                b j10 = j();
                if (j10 == null || (bArr = j10.b()) == null) {
                    bArr = new byte[0];
                }
                e10 = this.f29033c.e("BIOMETRIC_KEY_NAME", bArr);
            }
            Executor mainExecutor = androidx.core.content.a.getMainExecutor(activity);
            t.f(mainExecutor, "getMainExecutor(...)");
            new s.f(activity, mainExecutor, callback).a(i(z10), new f.c(e10));
        } catch (Exception unused) {
            clear();
            callback.a(13, "");
        }
    }

    @Override // md.f
    public void clear() {
        k(null);
        this.f29033c.a("BIOMETRIC_KEY_NAME");
    }

    @Override // md.f
    public void d(String userName, String password, Cipher cipher) {
        t.g(userName, "userName");
        t.g(password, "password");
        t.g(cipher, "cipher");
        String u10 = new com.google.gson.d().u(new C0659c(userName, password));
        e eVar = this.f29033c;
        t.d(u10);
        byte[] d10 = eVar.d(u10, cipher);
        byte[] iv = cipher.getIV();
        t.f(iv, "getIV(...)");
        k(new b(d10, iv));
    }

    @Override // md.f
    public boolean e() {
        return s.e.b(this.f29031a.a()).a(15) == 0;
    }

    @Override // md.f
    public f0 f() {
        return this.f29034d;
    }

    @Override // md.f
    public boolean g() {
        b j10 = j();
        if (!b() || j10 == null) {
            return false;
        }
        try {
            this.f29033c.e("BIOMETRIC_KEY_NAME", j10.b());
            return true;
        } catch (Exception unused) {
            clear();
            return false;
        }
    }
}
