package org.bouncycastle.bcpg.sig;

import org.bouncycastle.asn1.cmc.BodyPartID;
import org.bouncycastle.util.Pack;

/* JADX INFO: loaded from: classes3.dex */
class Utils {
    Utils() {
    }

    static boolean booleanFromByteArray(byte[] bArr) {
        if (bArr.length != 1) {
            throw new IllegalStateException("Byte array has unexpected length. Expected length 1, got " + bArr.length);
        }
        if (bArr[0] == 0) {
            return false;
        }
        if (bArr[0] == 1) {
            return true;
        }
        throw new IllegalStateException("Unexpected byte value for boolean encoding: " + ((int) bArr[0]));
    }

    static byte[] booleanToByteArray(boolean z) {
        byte[] bArr = new byte[1];
        if (z) {
            bArr[0] = 1;
        }
        return bArr;
    }

    static long timeFromBytes(byte[] bArr) {
        if (bArr.length == 4) {
            return ((long) Pack.bigEndianToInt(bArr, 0)) & BodyPartID.bodyIdMax;
        }
        throw new IllegalStateException("Byte array has unexpected length. Expected length 4, got " + bArr.length);
    }

    static byte[] timeToBytes(long j) {
        return Pack.intToBigEndian((int) j);
    }
}
