Exemplo n.º 1
0
def test_authenticate(cipher):
    plaintext = b'integrity'
    ciphertext = cipher.encrypt(plaintext=plaintext)
    payload = cipher._extract_payload(ciphertext=ciphertext)
    signature = cipher._extract_signature(ciphertext=ciphertext)
    assert cipher._authenticate(data=payload, signature=signature) is True

    bad_key = '02944c68b750474b85609147ce6d3aae875e6ae8ac63618086a58b1c1716402d'
    assert bad_key != cipher.key

    # Maybe we should allow setting of key/hmac_key in a method?
    new_cipher = crypto.AES256Cipher(key=bad_key)
    assert new_cipher._authenticate(data=payload, signature=signature) is False
Exemplo n.º 2
0
def test_bad_create_cipher():
    # Fails due to no key argument.
    with pytest.raises(TypeError):
        crypto.AES256Cipher()
Exemplo n.º 3
0
def test_bad_keys_for_cipher_exceptions(key):
    with pytest.raises(JakException) as excinfo:
        crypto.AES256Cipher(key=key)
    assert 'Key must be 64' in str(excinfo.value)
Exemplo n.º 4
0
def cipher():
    key = '4e9e5f6688e2a011856f7d58a27f7d9695013a893d89ad7652f2976a5c61f97f'
    return crypto.AES256Cipher(key=key)