X-Git-Url: https://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fdigest.py;fp=ctypescrypto%2Fdigest.py;h=f1c495c88ae6580c327717fa033227110a70cd97;hb=305f347018c18fa4183f8ec76177336881b713c9;hp=3589fc3fa1bc37a4d6e3d73e9a9586e1c432ab94;hpb=952f64afcfc4663797bf6cb36220e9c0e5116c17;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/digest.py b/ctypescrypto/digest.py index 3589fc3..f1c495c 100644 --- a/ctypescrypto/digest.py +++ b/ctypescrypto/digest.py @@ -15,7 +15,7 @@ algorithm would be available both to this module and hashlib. """ from ctypes import c_int, c_char_p, c_void_p, POINTER, c_long, c_longlong from ctypes import create_string_buffer, byref -from ctypescrypto import libcrypto +from ctypescrypto import libcrypto,pyver, bintype from ctypescrypto.exception import LibCryptoError from ctypescrypto.oid import Oid DIGEST_ALGORITHMS = ("MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512") @@ -56,7 +56,7 @@ class DigestType(object): self.digest_name = digest_name.longname() else: self.digest_name = str(digest_name) - self.digest = libcrypto.EVP_get_digestbyname(self.digest_name) + self.digest = libcrypto.EVP_get_digestbyname(self.digest_name.encode('us-ascii')) if self.digest is None: raise DigestError("Unknown digest: %s" % self.digest_name) @@ -124,8 +124,8 @@ class Digest(object): """ if self.digest_finalized: raise DigestError("No updates allowed") - if not isinstance(data, str): - raise TypeError("A string is expected") + if not isinstance(data, bintype): + raise TypeError("A byte string is expected") if length is None: length = len(data) elif length > len(data): @@ -180,7 +180,10 @@ class Digest(object): with hashlib """ from base64 import b16encode - return b16encode(self.digest(data)) + if pyver == 2: + return b16encode(self.digest(data)) + else: + return b16encode(self.digest(data)).decode('us-ascii') # Declare function result and argument types