X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fdigest.py;h=0098ab4109a36c15b3dd144624a62a18b5530317;hb=297667fab5c13886d82b037e74c84459f52e829c;hp=df4e58071a13c98e96b05e56710e86141407bd5b;hpb=eeb4a6511bf02295c802a6b55bfad226b01fa126;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/digest.py b/ctypescrypto/digest.py index df4e580..0098ab4 100644 --- a/ctypescrypto/digest.py +++ b/ctypescrypto/digest.py @@ -81,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"