From 3881917b59c49ab1616b61a696a74aa195c710e0 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Tue, 22 Apr 2014 12:00:43 +0800 Subject: Added more copy() tests --- cryptography/hazmat/backends/openssl/backend.py | 5 ++--- tests/hazmat/primitives/test_cmac.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 4137ad10..7d73c413 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -1309,16 +1309,15 @@ class _CMACContext(object): def copy(self): copied_ctx = self._backend._lib.CMAC_CTX_new() - self._backend._lib.CMAC_CTX_init(copied_ctx) copied_ctx = self._backend._ffi.gc( copied_ctx, self._backend._lib.CMAC_CTX_free ) res = self._backend._lib.CMAC_CTX_copy( copied_ctx, self._ctx ) - assert res == 0 + assert res == 1 return _CMACContext( - self._backend, self.algorithm, ctx=copied_ctx + self._backend, self._algorithm, ctx=copied_ctx ) diff --git a/tests/hazmat/primitives/test_cmac.py b/tests/hazmat/primitives/test_cmac.py index 25568114..f47f2c13 100644 --- a/tests/hazmat/primitives/test_cmac.py +++ b/tests/hazmat/primitives/test_cmac.py @@ -181,6 +181,13 @@ class TestCMAC(object): with pytest.raises(TypeError): cmac.verify(six.u('')) + def test_copy_with_backend(self, backend): + key = b"2b7e151628aed2a6abf7158809cf4f3c" + cmac = CMAC(AES(key), backend) + cmac.update(b"6bc1bee22e409f96e93d7e117393172a") + copy_cmac = cmac.copy() + assert cmac.finalize() == copy_cmac.finalize() + def test_copy(): @utils.register_interface(CMACBackend) -- cgit v1.2.3