Skip to content

Commit 42ad3b0

Browse files
authored
be consistent in our testing (#5409)
* be consistent in our testing we don't use default_backend this way in our tests * more black
1 parent 872835e commit 42ad3b0

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

tests/hazmat/primitives/test_pbkdf2hmac.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pytest
88

99
from cryptography.exceptions import AlreadyFinalized, InvalidKey, _Reasons
10-
from cryptography.hazmat.backends import default_backend
1110
from cryptography.hazmat.primitives import hashes
1211
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
1312

@@ -16,47 +15,45 @@
1615

1716

1817
class TestPBKDF2HMAC(object):
19-
def test_already_finalized(self):
20-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
18+
def test_already_finalized(self, backend):
19+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
2120
kdf.derive(b"password")
2221
with pytest.raises(AlreadyFinalized):
2322
kdf.derive(b"password2")
2423

25-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
24+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
2625
key = kdf.derive(b"password")
2726
with pytest.raises(AlreadyFinalized):
2827
kdf.verify(b"password", key)
2928

30-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
29+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
3130
kdf.verify(b"password", key)
3231
with pytest.raises(AlreadyFinalized):
3332
kdf.verify(b"password", key)
3433

35-
def test_unsupported_algorithm(self):
34+
def test_unsupported_algorithm(self, backend):
3635
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):
37-
PBKDF2HMAC(
38-
DummyHashAlgorithm(), 20, b"salt", 10, default_backend()
39-
)
36+
PBKDF2HMAC(DummyHashAlgorithm(), 20, b"salt", 10, backend)
4037

41-
def test_invalid_key(self):
42-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
38+
def test_invalid_key(self, backend):
39+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
4340
key = kdf.derive(b"password")
4441

45-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
42+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
4643
with pytest.raises(InvalidKey):
4744
kdf.verify(b"password2", key)
4845

49-
def test_unicode_error_with_salt(self):
46+
def test_unicode_error_with_salt(self, backend):
5047
with pytest.raises(TypeError):
51-
PBKDF2HMAC(hashes.SHA1(), 20, u"salt", 10, default_backend())
48+
PBKDF2HMAC(hashes.SHA1(), 20, u"salt", 10, backend)
5249

53-
def test_unicode_error_with_key_material(self):
54-
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend())
50+
def test_unicode_error_with_key_material(self, backend):
51+
kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, backend)
5552
with pytest.raises(TypeError):
5653
kdf.derive(u"unicode here")
5754

5855
def test_buffer_protocol(self, backend):
59-
kdf = PBKDF2HMAC(hashes.SHA1(), 10, b"salt", 10, default_backend())
56+
kdf = PBKDF2HMAC(hashes.SHA1(), 10, b"salt", 10, backend)
6057
data = bytearray(b"data")
6158
assert kdf.derive(data) == b"\xe9n\xaa\x81\xbbt\xa4\xf6\x08\xce"
6259

tests/hazmat/primitives/test_x963_vectors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pytest
1111

12-
from cryptography.hazmat.backends import default_backend
1312
from cryptography.hazmat.backends.interfaces import HashBackend
1413
from cryptography.hazmat.primitives import hashes
1514
from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF
@@ -58,7 +57,7 @@ def test_x963(self, backend, vector):
5857
algorithm=hashfn(),
5958
length=key_data_len,
6059
sharedinfo=sharedinfo,
61-
backend=default_backend(),
60+
backend=backend,
6261
)
6362
xkdf.verify(key, key_data)
6463

0 commit comments

Comments
 (0)