diff options
| author | David Reid <dreid@dreid.org> | 2014-01-28 14:51:25 -0800 |
|---|---|---|
| committer | David Reid <dreid@dreid.org> | 2014-02-03 10:05:27 -0800 |
| commit | ec4155a4035736011d8e3857965c60a766dd48f3 (patch) | |
| tree | 77e3d262a964a4061582202072c20d282e2d587e /cryptography | |
| parent | fec6d147eef3ada5b8d3c11714216f9438db58e3 (diff) | |
| download | cryptography-ec4155a4035736011d8e3857965c60a766dd48f3.tar.gz cryptography-ec4155a4035736011d8e3857965c60a766dd48f3.tar.bz2 cryptography-ec4155a4035736011d8e3857965c60a766dd48f3.zip | |
Aggressively type-check for text.
Diffstat (limited to 'cryptography')
| -rw-r--r-- | cryptography/hazmat/primitives/kdf/hkdf.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/kdf/hkdf.py b/cryptography/hazmat/primitives/kdf/hkdf.py index ce264f9b..959e8c9b 100644 --- a/cryptography/hazmat/primitives/kdf/hkdf.py +++ b/cryptography/hazmat/primitives/kdf/hkdf.py @@ -36,11 +36,19 @@ class HKDF(object): self._length = length + if isinstance(salt, six.text_type): + raise TypeError( + "Unicode-objects must be encoded before using them as a salt.") + if salt is None: salt = b"\x00" * (self._algorithm.digest_size // 8) self._salt = salt + if isinstance(info, six.text_type): + raise TypeError( + "Unicode-objects must be encoded before using them as info.") + if info is None: info = b"" @@ -85,6 +93,12 @@ class HKDF(object): return b"".join(output)[:self._length] def derive(self, key_material): + if isinstance(key_material, six.text_type): + raise TypeError( + "Unicode-objects must be encoded before using them as key " + "material." + ) + if self._used: raise exceptions.AlreadyFinalized @@ -92,5 +106,17 @@ class HKDF(object): return self._expand(self._extract(key_material)) def verify(self, key_material, expected_key): + if isinstance(key_material, six.text_type): + raise TypeError( + "Unicode-objects must be encoded before using them as key " + "material." + ) + + if isinstance(expected_key, six.text_type): + raise TypeError( + "Unicode-objects must be encoded before using them as " + "expected key material." + ) + if not constant_time.bytes_eq(self.derive(key_material), expected_key): raise exceptions.InvalidKey |
