From daac6d056753614077941da0a392c086dadbe965 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 20 Oct 2013 13:15:28 -0500 Subject: When copying a hash, pass the api through to the new object --- cryptography/primitives/hashes.py | 2 +- tests/primitives/test_hashes.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cryptography/primitives/hashes.py b/cryptography/primitives/hashes.py index 7133a916..3aa52462 100644 --- a/cryptography/primitives/hashes.py +++ b/cryptography/primitives/hashes.py @@ -37,7 +37,7 @@ class BaseHash(six.with_metaclass(abc.ABCMeta)): self._api.update_hash_context(self._ctx, data) def copy(self): - return self.__class__(ctx=self._copy_ctx()) + return self.__class__(api=self._api, ctx=self._copy_ctx()) def digest(self): return self._api.finalize_hash_context(self._copy_ctx(), diff --git a/tests/primitives/test_hashes.py b/tests/primitives/test_hashes.py index 03de8916..d721f7af 100644 --- a/tests/primitives/test_hashes.py +++ b/tests/primitives/test_hashes.py @@ -17,6 +17,8 @@ import pytest import six +from cryptography.bindings import _default_api + from cryptography.primitives import hashes from .utils import generate_base_hash_test @@ -33,6 +35,15 @@ class TestBaseHash(object): assert isinstance(m.hexdigest(), str) +class TestDefaultAPISHA1(object): + def test_default_api_creation(self): + """ + This test assumes the presence of SHA1 in the default API. + """ + h = hashes.SHA1() + assert h._api == _default_api + + class TestSHA1(object): test_SHA1 = generate_base_hash_test( hashes.SHA1, -- cgit v1.2.3