Example #1
0
def test_get_supported_ciphers():
    cl = get_supported_ciphers()
    assert cl and set(cl).issubset(set(CIPHER_NAME))
Example #2
0
def get_ciphers():
    return (name for name in sorted(get_supported_ciphers())
            if not name.endswith(b"CCM"))  # Not compiled by default.
Example #3
0
def test_cfb_raises_value_error_without_iv():
    with pytest.raises(ValueError):
        Cipher(b"AES-512-CFB", b"", MODE_CFB, b"")


def module_from_name(name):
    for cipher, mod in ((b"AES", mb.AES), (b"ARC4", mb.ARC4), (b"BLOWFISH",
                                                               mb.Blowfish),
                        (b"CAMELLIA", mb.Camellia), (b"DES-EDE3", mb.DES3),
                        (b"DES-EDE", mb.DES3dbl), (b"DES", mb.DES)):
        if name.startswith(cipher):
            return mod
    raise NotImplementedError


@pytest.fixture(params=(name for name in sorted(get_supported_ciphers())
                        if not name.endswith(b"CCM"))
                )  # Not compiled by default.
def cipher(request, randbytes):
    name = request.param
    cipher = Cipher(name, key=None, mode=None, iv=b"\x00")
    key = randbytes(cipher.key_size)
    iv = randbytes(cipher.iv_size)
    return module_from_name(name).new(key, cipher.mode, iv)


def is_streaming(cipher):
    return cipher.name.startswith(b"ARC") or cipher.mode is not MODE_ECB


def test_encrypt_decrypt(cipher, randbytes):
Example #4
0
def test_get_supported_ciphers():
    cl = get_supported_ciphers()
    assert cl and set(cl).issubset(set(CIPHER_NAME))