]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/digest.py
I've discovered Python's __all__ variable and make use of it in all modles
[oss/ctypescrypto.git] / ctypescrypto / digest.py
index df4e58071a13c98e96b05e56710e86141407bd5b..f5701037a6ee8d2238a9bfeed1813caa030263ad 100644 (file)
@@ -19,6 +19,7 @@ from ctypescrypto.exception import LibCryptoError
 from ctypescrypto.oid import Oid\r
 DIGEST_ALGORITHMS = ("MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512")\r
 \r
+__all__ = ['DigestError','Digest','DigestType','new']\r
 \r
 class DigestError(LibCryptoError):\r
        pass\r
@@ -81,15 +82,23 @@ class Digest:
        def __del__(self):\r
                self._clean_ctx()\r
 \r
-       def update(self, data):\r
+       def update(self, data, length=None):\r
                """\r
-                       Hashes given byte string as data\r
+                       Hashes given byte string \r
+\r
+                       @param data - string to hash\r
+                       @param length - if not specifed, entire string is hashed,\r
+                                       otherwise only first length bytes\r
                """\r
                if self.digest_finalized:\r
                        raise DigestError, "No updates allowed"\r
                if type(data) != type(""):\r
                        raise TypeError, "A string is expected"\r
-               result = libcrypto.EVP_DigestUpdate(self.ctx, c_char_p(data), len(data))\r
+               if length is None:\r
+                       length=len(data)\r
+               elif length> len(data):\r
+                       raise ValueError("Specified length is greater than length of data")\r
+               result = libcrypto.EVP_DigestUpdate(self.ctx, c_char_p(data), length)\r
                if result != 1:\r
                        raise DigestError, "Unable to update digest"\r
                \r