diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-29 11:08:30 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-29 11:08:30 -0700 |
commit | db279d0e383173df65f83541daa4b8f58fc070f4 (patch) | |
tree | 51fc87b9d313b75eb62a8f7f4099284046828b74 | |
parent | c83d447e0d5364b0a99ada6711384a38f772bb2f (diff) | |
download | cryptography-db279d0e383173df65f83541daa4b8f58fc070f4.tar.gz cryptography-db279d0e383173df65f83541daa4b8f58fc070f4.tar.bz2 cryptography-db279d0e383173df65f83541daa4b8f58fc070f4.zip |
Added a PaddingContext interface
-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__() |