Change teh exception
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py
index a39674f..c2e7149 100644
--- a/cryptography/exceptions.py
+++ b/cryptography/exceptions.py
@@ -18,7 +18,3 @@
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 77ecf27..b2599d2 100644
--- a/cryptography/hazmat/bindings/openssl/backend.py
+++ b/cryptography/hazmat/bindings/openssl/backend.py
@@ -19,7 +19,7 @@
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 @@
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 b0435b0..c6f5a7c 100644
--- a/docs/exceptions.rst
+++ b/docs/exceptions.rst
@@ -12,8 +12,3 @@
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 aebb4d4..4d79ac8 100644
--- a/docs/hazmat/primitives/padding.rst
+++ b/docs/hazmat/primitives/padding.rst
@@ -25,8 +25,14 @@
>>> 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 35b0d9a..732af33 100644
--- a/docs/hazmat/primitives/symmetric-encryption.rst
+++ b/docs/hazmat/primitives/symmetric-encryption.rst
@@ -99,13 +99,9 @@
.. 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 4c75620..ea40127 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -18,9 +18,7 @@
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 @@
)
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()