aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/hazmat/primitives/kdf/hkdf.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2018-12-02 19:20:33 +0800
committerAlex Gaynor <alex.gaynor@gmail.com>2018-12-02 06:20:33 -0500
commitafaa4c65b58e31f36a8162f88ad79829f68d0a86 (patch)
tree0660c30fe1382a2507c017b0df20c51544462258 /src/cryptography/hazmat/primitives/kdf/hkdf.py
parent3531439f8a09dd40102ac0e336cb962e86d8bf57 (diff)
downloadcryptography-afaa4c65b58e31f36a8162f88ad79829f68d0a86.tar.gz
cryptography-afaa4c65b58e31f36a8162f88ad79829f68d0a86.tar.bz2
cryptography-afaa4c65b58e31f36a8162f88ad79829f68d0a86.zip
centralize our bytes check (#4622)
this will make life a bit easier when we support bytearrays
Diffstat (limited to 'src/cryptography/hazmat/primitives/kdf/hkdf.py')
-rw-r--r--src/cryptography/hazmat/primitives/kdf/hkdf.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/cryptography/hazmat/primitives/kdf/hkdf.py b/src/cryptography/hazmat/primitives/kdf/hkdf.py
index 917b4e9c..27dc9c93 100644
--- a/src/cryptography/hazmat/primitives/kdf/hkdf.py
+++ b/src/cryptography/hazmat/primitives/kdf/hkdf.py
@@ -26,11 +26,10 @@ class HKDF(object):
self._algorithm = algorithm
- if not (salt is None or isinstance(salt, bytes)):
- raise TypeError("salt must be bytes.")
-
if salt is None:
salt = b"\x00" * self._algorithm.digest_size
+ else:
+ utils._check_bytes("salt", salt)
self._salt = salt
@@ -44,9 +43,7 @@ class HKDF(object):
return h.finalize()
def derive(self, key_material):
- if not isinstance(key_material, bytes):
- raise TypeError("key_material must be bytes.")
-
+ utils._check_bytes("key_material", key_material)
return self._hkdf_expand.derive(self._extract(key_material))
def verify(self, key_material, expected_key):
@@ -77,11 +74,10 @@ class HKDFExpand(object):
self._length = length
- if not (info is None or isinstance(info, bytes)):
- raise TypeError("info must be bytes.")
-
if info is None:
info = b""
+ else:
+ utils._check_bytes("info", info)
self._info = info
@@ -102,9 +98,7 @@ class HKDFExpand(object):
return b"".join(output)[:self._length]
def derive(self, key_material):
- if not isinstance(key_material, bytes):
- raise TypeError("key_material must be bytes.")
-
+ utils._check_bytes("key_material", key_material)
if self._used:
raise AlreadyFinalized