X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fdigest.py;h=0098ab4109a36c15b3dd144624a62a18b5530317;hb=297667fab5c13886d82b037e74c84459f52e829c;hp=4e33d92bb3e147b28a05fd22dd18ef315078dff2;hpb=22338425226b926b97b2e821e4d7d2ea9b2f1b88;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/digest.py b/ctypescrypto/digest.py index 4e33d92..0098ab4 100644 --- a/ctypescrypto/digest.py +++ b/ctypescrypto/digest.py @@ -1,5 +1,6 @@ """ - Implmenets interface to OpenSSL EVP_Digest* functions. + Implements interface to OpenSSL EVP_Digest* functions. + Interface made as close to hashlib as possible. This module is really an excess effort. Hashlib allows access to @@ -80,15 +81,23 @@ class Digest: def __del__(self): self._clean_ctx() - def update(self, data): + def update(self, data, length=None): """ - Hashes given byte string as data + Hashes given byte string + + @param data - string to hash + @param length - if not specifed, entire string is hashed, + otherwise only first length bytes """ if self.digest_finalized: raise DigestError, "No updates allowed" if type(data) != type(""): raise TypeError, "A string is expected" - result = libcrypto.EVP_DigestUpdate(self.ctx, c_char_p(data), len(data)) + if length is None: + length=len(data) + elif length> len(data): + raise ValueError("Specified length is greater than length of data") + result = libcrypto.EVP_DigestUpdate(self.ctx, c_char_p(data), length) if result != 1: raise DigestError, "Unable to update digest"