]> wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/digest.py
Addedet length parameter to Digest.update
[oss/ctypescrypto.git] / ctypescrypto / digest.py
index 4e33d92bb3e147b28a05fd22dd18ef315078dff2..0098ab4109a36c15b3dd144624a62a18b5530317 100644 (file)
@@ -1,5 +1,6 @@
 """\r
 """\r
-       Implmenets interface to OpenSSL EVP_Digest* functions.\r
+       Implements interface to OpenSSL EVP_Digest* functions.\r
+\r
        Interface  made as close to hashlib as possible.\r
 \r
        This module is really an excess effort. Hashlib allows access to\r
        Interface  made as close to hashlib as possible.\r
 \r
        This module is really an excess effort. Hashlib allows access to\r
@@ -80,15 +81,23 @@ class Digest:
        def __del__(self):\r
                self._clean_ctx()\r
 \r
        def __del__(self):\r
                self._clean_ctx()\r
 \r
-       def update(self, data):\r
+       def update(self, data, length=None):\r
                """\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
                """\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
                if result != 1:\r
                        raise DigestError, "Unable to update digest"\r
                \r