package I3;

import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;

/* JADX INFO: loaded from: classes.dex */
public final class s extends b {
    public static s b(j jVar, P.g gVar, Integer num) throws GeneralSecurityException {
        j jVar2 = j.f3335n;
        if (jVar != jVar2 && num == null) {
            throw new GeneralSecurityException("For given Variant " + jVar + " the value of idRequirement must be non-null");
        }
        if (jVar == jVar2 && num != null) {
            throw new GeneralSecurityException("For given Variant NO_PREFIX the value of idRequirement must be null");
        }
        V3.a aVar = (V3.a) gVar.f5246r;
        if (aVar.f6860a.length != 32) {
            throw new GeneralSecurityException("ChaCha20Poly1305 key must be constructed with key of length 32 bytes, not " + aVar.f6860a.length);
        }
        if (jVar == jVar2) {
            V3.a.a(new byte[0]);
        } else if (jVar == j.f3334m) {
            V3.a.a(ByteBuffer.allocate(5).put((byte) 0).putInt(num.intValue()).array());
        } else {
            if (jVar != j.f3333l) {
                throw new IllegalStateException("Unknown Variant: " + jVar);
            }
            V3.a.a(ByteBuffer.allocate(5).put((byte) 1).putInt(num.intValue()).array());
        }
        return new s();
    }
}
