Skip to content

Commit

Permalink
tests_kbkdf: add new tests
Browse files Browse the repository at this point in the history
- Test CounterLocation.MiddleFixed and blocation=
  • Loading branch information
jeanpaulgalea committed Aug 10, 2022
1 parent a8be6d1 commit b013a7b
Showing 1 changed file with 156 additions and 0 deletions.
156 changes: 156 additions & 0 deletions tests/hazmat/primitives/test_kbkdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,84 @@ def test_unsupported_parameters(self, backend):
backend=backend,
)

def test_missing_blocation(self, backend):
with pytest.raises(ValueError):
KBKDFHMAC(
hashes.SHA256(),
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
)

with pytest.raises(ValueError):
KBKDFHMAC(
hashes.SHA256(),
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
blocation=None,
)

def test_invalid_blocation(self, backend):
with pytest.raises(TypeError):
KBKDFHMAC(
hashes.SHA256(),
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
blocation="10", # type: ignore[arg-type]
)

def test_ignored_blocation_before(self, backend):
with pytest.raises(ValueError):
KBKDFHMAC(
hashes.SHA256(),
Mode.CounterMode,
32,
4,
4,
CounterLocation.BeforeFixed,
b"label",
b"context",
None,
backend=backend,
blocation=10,
)

def test_ignored_blocation_after(self, backend):
with pytest.raises(ValueError):
KBKDFHMAC(
hashes.SHA256(),
Mode.CounterMode,
32,
4,
4,
CounterLocation.AfterFixed,
b"label",
b"context",
None,
backend=backend,
blocation=10,
)

def test_unsupported_hash(self, backend):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):
KBKDFHMAC(
Expand Down Expand Up @@ -538,6 +616,84 @@ def test_unsupported_parameters(self, backend):
backend=backend,
)

def test_missing_blocation(self, backend):
with pytest.raises(ValueError):
KBKDFCMAC(
algorithms.AES,
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
)

with pytest.raises(ValueError):
KBKDFCMAC(
algorithms.AES,
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
blocation=None,
)

def test_invalid_blocation(self, backend):
with pytest.raises(TypeError):
KBKDFCMAC(
algorithms.AES,
Mode.CounterMode,
32,
4,
4,
CounterLocation.MiddleFixed,
b"label",
b"context",
None,
backend=backend,
blocation="10", # type: ignore[arg-type]
)

def test_ignored_blocation_before(self, backend):
with pytest.raises(ValueError):
KBKDFCMAC(
algorithms.AES,
Mode.CounterMode,
32,
4,
4,
CounterLocation.BeforeFixed,
b"label",
b"context",
None,
backend=backend,
blocation=10,
)

def test_ignored_blocation_after(self, backend):
with pytest.raises(ValueError):
KBKDFCMAC(
algorithms.AES,
Mode.CounterMode,
32,
4,
4,
CounterLocation.AfterFixed,
b"label",
b"context",
None,
backend=backend,
blocation=10,
)

def test_unsupported_algorithm(self, backend):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):
KBKDFCMAC(
Expand Down

0 comments on commit b013a7b

Please sign in to comment.