aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptography/exceptions.py4
-rw-r--r--cryptography/hazmat/bindings/openssl/backend.py6
-rw-r--r--docs/exceptions.rst5
-rw-r--r--docs/hazmat/primitives/padding.rst8
-rw-r--r--docs/hazmat/primitives/symmetric-encryption.rst10
-rw-r--r--tests/hazmat/primitives/test_block.py8
6 files changed, 16 insertions, 25 deletions
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py
index a39674f9..c2e71493 100644
--- a/cryptography/exceptions.py
+++ b/cryptography/exceptions.py
@@ -18,7 +18,3 @@ class UnsupportedAlgorithm(Exception):
class AlreadyFinalized(Exception):
pass
-
-
-class IncorrectPadding(Exception):
- pass
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py
index 77ecf277..b2599d22 100644
--- a/cryptography/hazmat/bindings/openssl/backend.py
+++ b/cryptography/hazmat/bindings/openssl/backend.py
@@ -19,7 +19,7 @@ import sys
import cffi
from cryptography import utils
-from cryptography.exceptions import UnsupportedAlgorithm, IncorrectPadding
+from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.bindings.interfaces import (
CipherBackend, HashBackend, HMACBackend
)
@@ -205,10 +205,10 @@ class Backend(object):
if lib == self.lib.ERR_LIB_EVP:
if func == self.lib.EVP_F_EVP_ENCRYPTFINAL_EX:
if reason == self.lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH:
- raise IncorrectPadding
+ raise ValueError
elif func == self.lib.EVP_F_EVP_DECRYPTFINAL_EX:
if reason == self.lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH:
- raise IncorrectPadding
+ raise ValueError
raise SystemError(
"Unknown error code from OpenSSL, you should probably file a bug."
diff --git a/docs/exceptions.rst b/docs/exceptions.rst
index b0435b0c..c6f5a7cc 100644
--- a/docs/exceptions.rst
+++ b/docs/exceptions.rst
@@ -12,8 +12,3 @@ Exceptions
This is raised when a backend doesn't support the requested algorithm (or
combination of algorithms).
-
-
-.. class:: IncorrectPadding
-
- This is raised when a block cipher's content isn't correctly padded.
diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst
index aebb4d4d..4d79ac8f 100644
--- a/docs/hazmat/primitives/padding.rst
+++ b/docs/hazmat/primitives/padding.rst
@@ -25,8 +25,14 @@ multiple of the block size.
>>> padder = padding.PKCS7(128).padder()
>>> padder.update(b"1111111111")
''
- >>> padder.finalize()
+ >>> padded_data = padder.finalize()
+ >>> padded_data
'1111111111\x06\x06\x06\x06\x06\x06'
+ >>> unpadder = padding.PKCS7(128).unpadder()
+ >>> unpadder.update(padded_data)
+ ''
+ >>> unpadder.finalize()
+ '1111111111'
:param block_size: The size of the block in bits that the data is being
padded to.
diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst
index 35b0d9a8..732af33c 100644
--- a/docs/hazmat/primitives/symmetric-encryption.rst
+++ b/docs/hazmat/primitives/symmetric-encryption.rst
@@ -99,13 +99,9 @@ an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
.. method:: finalize()
:return bytes: Returns the remainder of the data.
- :raises cryptography.exceptions.IncorrectPadding: This is raised when
- the data provided
- isn't correctly
- padded to be a
- multiple of the
- algorithm's block
- size.
+ :raises ValueError: This is raised when the data provided isn't
+ correctly padded to be a multiple of the
+ algorithm's block size.
Once ``finalize`` is called this object can no longer be used and
:meth:`update` and :meth:`finalize` will raise
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index 4c756203..ea40127e 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -18,9 +18,7 @@ import binascii
import pytest
from cryptography import utils
-from cryptography.exceptions import (
- UnsupportedAlgorithm, AlreadyFinalized, IncorrectPadding
-)
+from cryptography.exceptions import UnsupportedAlgorithm, AlreadyFinalized
from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers import (
Cipher, algorithms, modes
@@ -119,10 +117,10 @@ class TestCipherContext(object):
)
encryptor = cipher.encryptor()
encryptor.update(b"1")
- with pytest.raises(IncorrectPadding):
+ with pytest.raises(ValueError):
encryptor.finalize()
decryptor = cipher.decryptor()
decryptor.update(b"1")
- with pytest.raises(IncorrectPadding):
+ with pytest.raises(ValueError):
decryptor.finalize()