diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-21 21:32:21 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-21 21:32:21 -0700 |
commit | e524d73d76d63c6399a55cd80cec53cf39c98659 (patch) | |
tree | 7532b109bcddc17995f95b3178b52c739a626bd3 /cryptography | |
parent | f3421788033b233d1aa51eae08c4fbe7b9748536 (diff) | |
parent | d4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1 (diff) | |
download | cryptography-e524d73d76d63c6399a55cd80cec53cf39c98659.tar.gz cryptography-e524d73d76d63c6399a55cd80cec53cf39c98659.tar.bz2 cryptography-e524d73d76d63c6399a55cd80cec53cf39c98659.zip |
Merge pull request #147 from reaperhulk/hash-improvements
Provide data to hash constructor + reject unicode ala hashlib
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/primitives/hashes.py | 6 |
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): |