package kk;

import fk.o;
import fk.p;
import fk.q;
import fk.r;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.logging.Logger;
import mk.i0;
import nk.g;

/* loaded from: classes3.dex */
class d implements q {

    /* renamed from: a, reason: collision with root package name */
    private static final Logger f25877a = Logger.getLogger(d.class.getName());

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static class b implements o {

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

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

        @Override // fk.o
        public void a(byte[] bArr, byte[] bArr2) {
            if (bArr.length <= 5) {
                throw new GeneralSecurityException("tag too short");
            }
            byte[] copyOf = Arrays.copyOf(bArr, 5);
            byte[] copyOfRange = Arrays.copyOfRange(bArr, 5, bArr.length);
            for (p.b bVar : this.f25878a.c(copyOf)) {
                try {
                    if (bVar.b().equals(i0.LEGACY)) {
                        ((o) bVar.c()).a(copyOfRange, g.a(bArr2, this.f25879b));
                        return;
                    } else {
                        ((o) bVar.c()).a(copyOfRange, bArr2);
                        return;
                    }
                } catch (GeneralSecurityException e10) {
                    d.f25877a.info("tag prefix matches a key, but cannot verify: " + e10);
                }
            }
            Iterator it = this.f25878a.e().iterator();
            while (it.hasNext()) {
                try {
                    ((o) ((p.b) it.next()).c()).a(bArr, bArr2);
                    return;
                } catch (GeneralSecurityException unused) {
                }
            }
            throw new GeneralSecurityException("invalid MAC");
        }

        @Override // fk.o
        public byte[] b(byte[] bArr) {
            return this.f25878a.b().b().equals(i0.LEGACY) ? g.a(this.f25878a.b().a(), ((o) this.f25878a.b().c()).b(g.a(bArr, this.f25879b))) : g.a(this.f25878a.b().a(), ((o) this.f25878a.b().c()).b(bArr));
        }

        private b(p pVar) {
            this.f25879b = new byte[]{0};
            this.f25878a = pVar;
        }
    }

    d() {
    }

    public static void e() {
        r.r(new d());
    }

    @Override // fk.q
    public Class a() {
        return o.class;
    }

    @Override // fk.q
    public Class b() {
        return o.class;
    }

    @Override // fk.q
    /* renamed from: f, reason: merged with bridge method [inline-methods] */
    public o c(p pVar) {
        return new b(pVar);
    }
}
