From db279d0e383173df65f83541daa4b8f58fc070f4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 29 Oct 2013 11:08:30 -0700 Subject: Added a PaddingContext interface --- cryptography/hazmat/primitives/interfaces.py | 14 ++++++++++++++ cryptography/hazmat/primitives/padding.py | 4 ++++ 2 files changed, 18 insertions(+) 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__() -- cgit v1.2.3