diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-01-19 12:44:04 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-01-19 12:44:04 -0600 |
commit | 16bf40c85c381c7ae84c3b69e0e4824bc6693624 (patch) | |
tree | 14bdfefd6574c6dbe3beb647b4483bcf514a969f | |
parent | 70b6cf82795b7069c504b5700afb671e8a585716 (diff) | |
download | cryptography-16bf40c85c381c7ae84c3b69e0e4824bc6693624.tar.gz cryptography-16bf40c85c381c7ae84c3b69e0e4824bc6693624.tar.bz2 cryptography-16bf40c85c381c7ae84c3b69e0e4824bc6693624.zip |
rename a few things in an attempt to improve clarity
-rw-r--r-- | cryptography/hazmat/backends/commoncrypto/backend.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py index 6ca1bfa7..10c6596f 100644 --- a/cryptography/hazmat/backends/commoncrypto/backend.py +++ b/cryptography/hazmat/backends/commoncrypto/backend.py @@ -30,35 +30,37 @@ class Backend(object): CommonCrypto API wrapper. """ name = "commoncrypto" - hashtuple = namedtuple("HashClass", ["struct", "init", "update", "final"]) + HashMethods = namedtuple( + "HashMethods", ["ctx", "hash_init", "hash_update", "hash_final"] + ) def __init__(self): self._binding = Binding() self._ffi = self._binding.ffi self._lib = self._binding.lib - self.hash_methods = { - "md5": self.hashtuple( + self.hash_mapping = { + "md5": self.HashMethods( "CC_MD5_CTX *", self._lib.CC_MD5_Init, self._lib.CC_MD5_Update, self._lib.CC_MD5_Final ), - "sha1": self.hashtuple( + "sha1": self.HashMethods( "CC_SHA1_CTX *", self._lib.CC_SHA1_Init, self._lib.CC_SHA1_Update, self._lib.CC_SHA1_Final ), - "sha224": self.hashtuple( + "sha224": self.HashMethods( "CC_SHA256_CTX *", self._lib.CC_SHA224_Init, self._lib.CC_SHA224_Update, self._lib.CC_SHA224_Final ), - "sha256": self.hashtuple( + "sha256": self.HashMethods( "CC_SHA256_CTX *", self._lib.CC_SHA256_Init, self._lib.CC_SHA256_Update, self._lib.CC_SHA256_Final ), - "sha384": self.hashtuple( + "sha384": self.HashMethods( "CC_SHA512_CTX *", self._lib.CC_SHA384_Init, self._lib.CC_SHA384_Update, self._lib.CC_SHA384_Final ), - "sha512": self.hashtuple( + "sha512": self.HashMethods( "CC_SHA512_CTX *", self._lib.CC_SHA512_Init, self._lib.CC_SHA512_Update, self._lib.CC_SHA512_Final ), @@ -66,7 +68,7 @@ class Backend(object): def hash_supported(self, algorithm): try: - self.hash_methods[algorithm.name] + self.hash_mapping[algorithm.name] return True except KeyError: return False @@ -83,21 +85,21 @@ class _HashContext(object): if ctx is None: try: - methods = self._backend.hash_methods[self.algorithm.name] + methods = self._backend.hash_mapping[self.algorithm.name] except KeyError: raise UnsupportedAlgorithm( "{0} is not a supported hash on this backend".format( algorithm.name) ) - ctx = self._backend._ffi.new(methods.struct) - res = methods.init(ctx) + ctx = self._backend._ffi.new(methods.ctx) + res = methods.hash_init(ctx) assert res == 1 self._ctx = ctx def copy(self): - methods = self._backend.hash_methods[self.algorithm.name] - new_ctx = self._backend._ffi.new(methods.struct) + methods = self._backend.hash_mapping[self.algorithm.name] + new_ctx = self._backend._ffi.new(methods.ctx) # CommonCrypto has no APIs for copying hashes, so we have to copy the # underlying struct. new_ctx[0] = self._ctx[0] @@ -105,15 +107,15 @@ class _HashContext(object): return _HashContext(self._backend, self.algorithm, ctx=new_ctx) def update(self, data): - methods = self._backend.hash_methods[self.algorithm.name] - res = methods.update(self._ctx, data, len(data)) + methods = self._backend.hash_mapping[self.algorithm.name] + res = methods.hash_update(self._ctx, data, len(data)) assert res == 1 def finalize(self): - methods = self._backend.hash_methods[self.algorithm.name] + methods = self._backend.hash_mapping[self.algorithm.name] buf = self._backend._ffi.new("unsigned char[]", self.algorithm.digest_size) - res = methods.final(buf, self._ctx) + res = methods.hash_final(buf, self._ctx) assert res == 1 return self._backend._ffi.buffer(buf)[:] |