diff options
-rw-r--r-- | cryptography/hazmat/primitives/interfaces.py | 14 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/padding.py | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index 49c19d0e..217490fd 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -45,3 +45,17 @@ class CipherContext(six.with_metaclass(abc.ABCMeta)): """ finalize return bytes """ + + +class PaddingContext(six.with_metaclass(abc.ABCMeta)): + @abc.abstractmethod + def update(self, data): + """ + update takes bytes and return bytes + """ + + @abc.abstractmethod + def finalize(self): + """ + finalize return bytes + """ diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py index 09e4b9f0..8e2219e1 100644 --- a/cryptography/hazmat/primitives/padding.py +++ b/cryptography/hazmat/primitives/padding.py @@ -13,6 +13,8 @@ import six +from cryptography.hazmat.primitives import interfaces + class PKCS7(object): def __init__(self, block_size): @@ -40,6 +42,7 @@ class PKCS7(object): return unpadder.update(data) + unpadder.finalize() +@interfaces.register(interfaces.PaddingContext) class _PaddingContext(object): def __init__(self, block_size): super(_PaddingContext, self).__init__() @@ -70,6 +73,7 @@ class _PaddingContext(object): return result +@interfaces.register(interfaces.PaddingContext) class _UnpaddingContext(object): def __init__(self, block_size): super(_UnpaddingContext, self).__init__() |