Skip to content

Commit

Permalink
test failure / encrypt decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Synss committed Sep 21, 2019
1 parent 4af6e48 commit 6e58c5c
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions tests/test_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,43 @@ def data(self, cipher, mode, randbytes):
# `block_size` is limited for ECB because it is a block cipher.
return randbytes(cipher.block_size if mode is mb.Mode.ECB else 20000)

def test_unsupported_mode(self, module, key, unsupported_mode, iv):
with pytest.raises(TLSError):
module.new(key, unsupported_mode, iv)

def test_mode_accessor(self, cipher, mode):
assert cipher.mode is mode

def test_iv_size_accessor(self, cipher, iv_size):
assert cipher.iv_size == iv_size

def test_invalid_key_size(self, module, invalid_key, mode, iv):
with pytest.raises(TLSError):
module.new(invalid_key, mode, iv)

def test_key_size_accessor(self, cipher, key_size):
assert cipher.key_size == key_size

def test_name_accessor(self, cipher):
assert cipher.name in CIPHER_NAME

def test_str(self, cipher):
assert str(cipher) == cipher.name.decode("ascii")

def test_type_accessor(self, cipher):
assert CIPHER_NAME[cipher._type] == cipher.name

def test_unsupported_mode(self, module, key, unsupported_mode, iv):
with pytest.raises(TLSError):
module.new(key, unsupported_mode, iv)

def test_invalid_key_size(self, module, invalid_key, mode, iv):
with pytest.raises(TLSError):
module.new(invalid_key, mode, iv)

def test_encrypt_decrypt(self, cipher, data):
assert cipher.decrypt(cipher.encrypt(data)) == data

def test_encrypt_nothing_raises(self, cipher):
with pytest.raises(TLSError):
cipher.encrypt(b"")

def test_decrypt_nothing_raises(self, cipher):
with pytest.raises(TLSError):
cipher.decrypt(b"")

def test_module_level_block_size(self, module, cipher):
assert module.block_size == cipher.block_size

Expand All @@ -167,6 +181,11 @@ def test_encrypt_decrypt(self, cipher, data):
msg, tag = cipher.encrypt(data)
assert cipher.decrypt(msg, tag) == data

def test_decrypt_nothing_raises(self, cipher, data):
msg, tag = cipher.encrypt(data)
with pytest.raises(TLSError):
cipher.decrypt(b"", tag)


@pytest.mark.skipif(
not mbedtls.has_feature("aes"), reason="requires AES support in libmbedtls"
Expand Down

0 comments on commit 6e58c5c

Please sign in to comment.