aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-21 21:32:21 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-21 21:32:21 -0700
commite524d73d76d63c6399a55cd80cec53cf39c98659 (patch)
tree7532b109bcddc17995f95b3178b52c739a626bd3 /cryptography
parentf3421788033b233d1aa51eae08c4fbe7b9748536 (diff)
parentd4cb34d51ae6695a6cda8e3b46eeb0b45a5935f1 (diff)
downloadcryptography-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.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):