Esempio n. 1
0
def test_to_bytes_overflow():
    value = unhexlify(b"DEEADBEEFF")
    mpi = MPI.from_bytes(value, byteorder="big")
    with pytest.raises(OverflowError):
        mpi.to_bytes(2, byteorder="big")
Esempio n. 2
0
def test_from_empty_bytes():
    value = b""
    big = MPI.from_bytes(value, byteorder="big")
    little = MPI.from_bytes(value, byteorder="little")
    assert big == little == 0
    assert big.bit_length() == little.bit_length() == 0
Esempio n. 3
0
def test_from_bytes():
    value = unhexlify(b"DEADBEEF")
    mpi = MPI.from_bytes(value, byteorder="big")
    assert mpi.to_bytes(4, byteorder="big") == unhexlify(b"DEADBEEF")
    assert mpi.to_bytes(4, byteorder="little") == unhexlify(b"EFBEADDE")
    assert mpi == int(hexlify(value), 16)
Esempio n. 4
0
def test_from_bytes():
    value = unhexlify(b"DEEADBEEFF")
    mpi = MPI.from_bytes(value, byteorder="big")
    assert mpi.to_bytes(5, byteorder="big") == value
    assert mpi.to_bytes(5, byteorder="little") == value[::-1]
    assert mpi == int(hexlify(value), 16)