aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-19 23:05:12 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-19 23:17:00 -0500
commitd4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1 (patch)
treed26ed4e241a32915aa8addccebaf9efbca3b71f7 /cryptography
parent746815b8f2b6a485b41e37c67969ed21338946db (diff)
downloadcryptography-d4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1.tar.gz
cryptography-d4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1.tar.bz2
cryptography-d4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1.zip
Allow data to be passed in the constructor & reject unicode ala hashlib
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/primitives/hashes.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/cryptography/primitives/hashes.py b/cryptography/primitives/hashes.py
index e8c1f929..c4bd8ad0 100644
--- a/cryptography/primitives/hashes.py
+++ b/cryptography/primitives/hashes.py
@@ -23,13 +23,17 @@ from cryptography.bindings import _default_api
class BaseHash(six.with_metaclass(abc.ABCMeta)):
- def __init__(self, api=None, ctx=None):
+ def __init__(self, data=None, api=None, ctx=None):
if api is None:
api = _default_api
self._api = api
self._ctx = self._api.create_hash_context(self) if ctx is None else ctx
+ if data is not None:
+ self.update(data)
def update(self, data):
+ if isinstance(data, six.text_type):
+ raise TypeError("Unicode-objects must be encoded before hashing")
self._api.update_hash_context(self._ctx, data)
def copy(self):