summaryrefslogtreecommitdiff
path: root/src/cryptography/hazmat/backends/openssl/hashes.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptography/hazmat/backends/openssl/hashes.py')
-rw-r--r--src/cryptography/hazmat/backends/openssl/hashes.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/hashes.py b/src/cryptography/hazmat/backends/openssl/hashes.py
index 549fa2bf5..764dce0ed 100644
--- a/src/cryptography/hazmat/backends/openssl/hashes.py
+++ b/src/cryptography/hazmat/backends/openssl/hashes.py
@@ -18,19 +18,21 @@ class _HashContext(object):
self._backend = backend
if ctx is None:
- ctx = self._backend._lib.Cryptography_EVP_MD_CTX_new()
+ ctx = self._backend._lib.EVP_MD_CTX_new()
ctx = self._backend._ffi.gc(
- ctx, self._backend._lib.Cryptography_EVP_MD_CTX_free
+ ctx, self._backend._lib.EVP_MD_CTX_free
)
evp_md = self._backend._evp_md_from_algorithm(algorithm)
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
- "{0} is not a supported hash on this backend.".format(
- algorithm.name),
- _Reasons.UNSUPPORTED_HASH
+ "{} is not a supported hash on this backend.".format(
+ algorithm.name
+ ),
+ _Reasons.UNSUPPORTED_HASH,
)
- res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
- self._backend._ffi.NULL)
+ res = self._backend._lib.EVP_DigestInit_ex(
+ ctx, evp_md, self._backend._ffi.NULL
+ )
self._backend.openssl_assert(res != 0)
self._ctx = ctx
@@ -38,9 +40,9 @@ class _HashContext(object):
algorithm = utils.read_only_property("_algorithm")
def copy(self):
- copied_ctx = self._backend._lib.Cryptography_EVP_MD_CTX_new()
+ copied_ctx = self._backend._lib.EVP_MD_CTX_new()
copied_ctx = self._backend._ffi.gc(
- copied_ctx, self._backend._lib.Cryptography_EVP_MD_CTX_free
+ copied_ctx, self._backend._lib.EVP_MD_CTX_free
)
res = self._backend._lib.EVP_MD_CTX_copy_ex(copied_ctx, self._ctx)
self._backend.openssl_assert(res != 0)
@@ -58,21 +60,23 @@ class _HashContext(object):
# extendable output functions use a different finalize
return self._finalize_xof()
else:
- buf = self._backend._ffi.new("unsigned char[]",
- self._backend._lib.EVP_MAX_MD_SIZE)
+ buf = self._backend._ffi.new(
+ "unsigned char[]", self._backend._lib.EVP_MAX_MD_SIZE
+ )
outlen = self._backend._ffi.new("unsigned int *")
res = self._backend._lib.EVP_DigestFinal_ex(self._ctx, buf, outlen)
self._backend.openssl_assert(res != 0)
self._backend.openssl_assert(
outlen[0] == self.algorithm.digest_size
)
- return self._backend._ffi.buffer(buf)[:outlen[0]]
+ return self._backend._ffi.buffer(buf)[: outlen[0]]
def _finalize_xof(self):
- buf = self._backend._ffi.new("unsigned char[]",
- self.algorithm.digest_size)
+ buf = self._backend._ffi.new(
+ "unsigned char[]", self.algorithm.digest_size
+ )
res = self._backend._lib.EVP_DigestFinalXOF(
self._ctx, buf, self.algorithm.digest_size
)
self._backend.openssl_assert(res != 0)
- return self._backend._ffi.buffer(buf)[:self.algorithm.digest_size]
+ return self._backend._ffi.buffer(buf)[: self.algorithm.digest_size]