package u2;

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

/* JADX INFO: loaded from: classes.dex */
public final class w extends AbstractC1066b {
    public static w b(g gVar, g3.c cVar, Integer num) throws GeneralSecurityException {
        g gVar2 = g.f10337y;
        if (gVar != gVar2 && num == null) {
            throw new GeneralSecurityException("For given Variant " + gVar + " the value of idRequirement must be non-null");
        }
        if (gVar == gVar2 && num != null) {
            throw new GeneralSecurityException("For given Variant NO_PREFIX the value of idRequirement must be null");
        }
        H2.a aVar = (H2.a) cVar.f6465l;
        if (aVar.f873a.length != 32) {
            throw new GeneralSecurityException("XChaCha20Poly1305 key must be constructed with key of length 32 bytes, not " + aVar.f873a.length);
        }
        if (gVar == gVar2) {
            H2.a.a(new byte[0]);
        } else if (gVar == g.f10336x) {
            H2.a.a(ByteBuffer.allocate(5).put((byte) 0).putInt(num.intValue()).array());
        } else {
            if (gVar != g.f10335w) {
                throw new IllegalStateException("Unknown Variant: " + gVar);
            }
            H2.a.a(ByteBuffer.allocate(5).put((byte) 1).putInt(num.intValue()).array());
        }
        return new w();
    }
}
