aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2013-11-22 13:30:46 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2013-11-29 17:19:45 -0600
commit24316fd1945909ef720ceb0e294752c4d3b6bbb2 (patch)
tree64eeeaeb3a06bc770c1bfaa0fc81ef1fa5ce4457 /cryptography
parentcc9ec987e82d1c4e2d42e6ef41664a090425287c (diff)
downloadcryptography-24316fd1945909ef720ceb0e294752c4d3b6bbb2.tar.gz
cryptography-24316fd1945909ef720ceb0e294752c4d3b6bbb2.tar.bz2
cryptography-24316fd1945909ef720ceb0e294752c4d3b6bbb2.zip
_AEADCipherContext refactor
* No longer extends _CipherContext * Remove _tag from _CipherContext * This change duplicates a small amount of code from _CipherContext
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/primitives/ciphers/base.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py
index 3a27030a..89e56547 100644
--- a/cryptography/hazmat/primitives/ciphers/base.py
+++ b/cryptography/hazmat/primitives/ciphers/base.py
@@ -60,7 +60,6 @@ class Cipher(object):
class _CipherContext(object):
def __init__(self, ctx):
self._ctx = ctx
- self._tag = None
def update(self, data):
if self._ctx is None:
@@ -71,14 +70,30 @@ class _CipherContext(object):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")
data = self._ctx.finalize()
- self._tag = self._ctx._tag
self._ctx = None
return data
@utils.register_interface(interfaces.AEADCipherContext)
@utils.register_interface(interfaces.CipherContext)
-class _AEADCipherContext(_CipherContext):
+class _AEADCipherContext(object):
+ def __init__(self, ctx):
+ self._ctx = ctx
+ self._tag = None
+
+ def update(self, data):
+ if self._ctx is None:
+ raise AlreadyFinalized("Context was already finalized")
+ return self._ctx.update(data)
+
+ def finalize(self):
+ if self._ctx is None:
+ raise AlreadyFinalized("Context was already finalized")
+ data = self._ctx.finalize()
+ self._tag = self._ctx._tag
+ self._ctx = None
+ return data
+
def add_data(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")