diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2017-05-20 14:53:33 -0700 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2017-05-20 14:53:33 -0700 |
commit | 453d2ac482bf4c84207cb2ac7974f6136f27ce5c (patch) | |
tree | 29be901862371f31f27df8b66770a9af65e17b17 /tests/hazmat/primitives/test_ciphers.py | |
parent | c7dd9de42ff93d94757a339fe3bf39dc42cd86f9 (diff) | |
download | cryptography-453d2ac482bf4c84207cb2ac7974f6136f27ce5c.tar.gz cryptography-453d2ac482bf4c84207cb2ac7974f6136f27ce5c.tar.bz2 cryptography-453d2ac482bf4c84207cb2ac7974f6136f27ce5c.zip |
Fixed #3533 -- made GCM mode object immutable (#3553)
* Fixed #3533 -- made GCM mode object immutable
* flake8
* Fix for older openssl
* fix
* fix
* sigh, fix
* fixed
* dropped negation
* computers are bad
* A test
* This implements an interface
Diffstat (limited to 'tests/hazmat/primitives/test_ciphers.py')
-rw-r--r-- | tests/hazmat/primitives/test_ciphers.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py index 7f51576a..60faa0c5 100644 --- a/tests/hazmat/primitives/test_ciphers.py +++ b/tests/hazmat/primitives/test_ciphers.py @@ -11,7 +11,7 @@ import cffi import pytest -from cryptography.exceptions import _Reasons +from cryptography.exceptions import AlreadyFinalized, _Reasons from cryptography.hazmat.backends.interfaces import CipherBackend from cryptography.hazmat.primitives import ciphers from cryptography.hazmat.primitives.ciphers import modes @@ -196,6 +196,28 @@ class TestCipherUpdateInto(object): assert res == len(pt) assert bytes(buf)[:res] == pt + @pytest.mark.supported( + only_if=lambda backend: backend.cipher_supported( + AES(b"\x00" * 16), modes.GCM(b"0" * 12) + ), + skip_message="Does not support AES GCM", + ) + def test_finalize_with_tag_already_finalized(self, backend): + key = binascii.unhexlify(b"e98b72a9881a84ca6b76e0f43e68647a") + iv = binascii.unhexlify(b"8b23299fde174053f3d652ba") + encryptor = ciphers.Cipher( + AES(key), modes.GCM(iv), backend + ).encryptor() + ciphertext = encryptor.update(b"abc") + encryptor.finalize() + + decryptor = ciphers.Cipher( + AES(key), modes.GCM(iv, tag=encryptor.tag), backend + ).decryptor() + decryptor.update(ciphertext) + decryptor.finalize() + with pytest.raises(AlreadyFinalized): + decryptor.finalize_with_tag(encryptor.tag) + @pytest.mark.parametrize( "params", load_vectors_from_file( |