change api.supports_hash to take a hash class rather than a str
* This change means hash class names will be byte strings and we no
longer need to encode to ascii on hashobject.name in
create_hash_context
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index 548a9e6..8445836 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -139,14 +139,14 @@
assert res != 0
return self.ffi.buffer(buf)[:outlen[0]]
- def supports_hash(self, hashname):
+ def supports_hash(self, hash_cls):
return (self.ffi.NULL !=
- self.lib.EVP_get_digestbyname(hashname.encode("ascii")))
+ self.lib.EVP_get_digestbyname(hash_cls.name))
def create_hash_context(self, hashobject):
ctx = self.lib.EVP_MD_CTX_create()
ctx = self.ffi.gc(ctx, self.lib.EVP_MD_CTX_destroy)
- evp_md = self.lib.EVP_get_digestbyname(hashobject.name.encode("ascii"))
+ evp_md = self.lib.EVP_get_digestbyname(hashobject.name)
assert evp_md != self.ffi.NULL
res = self.lib.EVP_DigestInit_ex(ctx, evp_md, self.ffi.NULL)
assert res != 0
diff --git a/cryptography/primitives/hashes.py b/cryptography/primitives/hashes.py
index d74287f..f5cf135 100644
--- a/cryptography/primitives/hashes.py
+++ b/cryptography/primitives/hashes.py
@@ -43,6 +43,6 @@
class SHA1(BaseHash):
- name = "sha1"
+ name = b"sha1"
digest_size = 20
block_size = 64
diff --git a/tests/primitives/test_hash_vectors.py b/tests/primitives/test_hash_vectors.py
index 8198b08..9a925e2 100644
--- a/tests/primitives/test_hash_vectors.py
+++ b/tests/primitives/test_hash_vectors.py
@@ -30,6 +30,6 @@
"SHA1ShortMsg.rsp",
],
hashes.SHA1,
- only_if=lambda api: api.supports_hash("sha1"),
+ only_if=lambda api: api.supports_hash(hashes.SHA1),
skip_message="Does not support SHA1",
)
diff --git a/tests/primitives/test_hashes.py b/tests/primitives/test_hashes.py
index 1bc2e9e..4ad5c89 100644
--- a/tests/primitives/test_hashes.py
+++ b/tests/primitives/test_hashes.py
@@ -23,6 +23,6 @@
hashes.SHA1,
digest_size=20,
block_size=64,
- only_if=lambda api: api.supports_hash("sha1"),
+ only_if=lambda api: api.supports_hash(hashes.SHA1),
skip_message="Does not support SHA1",
)