コード例 #1
0
class TestSM3:
    test_sm3 = generate_hash_test(
        load_hash_vectors,
        os.path.join("hashes", "SM3"),
        ["oscca.txt"],
        hashes.SM3(),
    )
コード例 #2
0
ファイル: test_hashes.py プロジェクト: Sp1l/py-cryptography
class TestSM3(object):
    test_sm3 = generate_base_hash_test(
        hashes.SM3(),
        digest_size=32,
    )
コード例 #3
0
ファイル: test_hashes.py プロジェクト: Sp1l/py-cryptography
    h = hashes.Hash(hashes.SHA256(), backend)
    h.update(bytearray(data))
    assert h.finalize() == binascii.unhexlify(
        b"dff2e73091f6c05e528896c4c831b9448653dc2ff043528f6769437bc7b975c2")


class TestSHAKE(object):
    @pytest.mark.parametrize("xof", [hashes.SHAKE128, hashes.SHAKE256])
    def test_invalid_digest_type(self, xof):
        with pytest.raises(TypeError):
            xof(digest_size=object())

    @pytest.mark.parametrize("xof", [hashes.SHAKE128, hashes.SHAKE256])
    def test_invalid_digest_size(self, xof):
        with pytest.raises(ValueError):
            xof(digest_size=-5)

        with pytest.raises(ValueError):
            xof(digest_size=0)


@pytest.mark.supported(
    only_if=lambda backend: backend.hash_supported(hashes.SM3()),
    skip_message="Does not support SM3",
)
class TestSM3(object):
    test_sm3 = generate_base_hash_test(
        hashes.SM3(),
        digest_size=32,
    )