aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-01-01 12:13:00 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-01-01 12:13:00 -0800
commitad8e76c333c4e969532d9239f686eea820f6f870 (patch)
tree07686b23c86b1b2a29a6c000336bf64c5ca9023b
parente23eef2ccf3503d164df7d55bb723a1daf365438 (diff)
downloadcryptography-ad8e76c333c4e969532d9239f686eea820f6f870.tar.gz
cryptography-ad8e76c333c4e969532d9239f686eea820f6f870.tar.bz2
cryptography-ad8e76c333c4e969532d9239f686eea820f6f870.zip
Rearrange
-rw-r--r--cryptography/hazmat/primitives/ciphers/base.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py
index d1ca6d2a..1da0802c 100644
--- a/cryptography/hazmat/primitives/ciphers/base.py
+++ b/cryptography/hazmat/primitives/ciphers/base.py
@@ -30,30 +30,32 @@ class Cipher(object):
self._backend = backend
def encryptor(self):
+ if isinstance(self.mode, interfaces.ModeWithAuthenticationTag):
+ if self.mode.tag is not None:
+ raise ValueError(
+ "Authentication tag must be None when encrypting"
+ )
ctx = self._backend.create_symmetric_encryption_ctx(
self.algorithm, self.mode
)
- return self._wrap_ctx(ctx, True)
+ return self._wrap_ctx(ctx, encrypt=True)
def decryptor(self):
+ if isinstance(self.mode, interfaces.ModeWithAuthenticationTag):
+ if self.mode.tag is None:
+ raise ValueError(
+ "Authentication tag must be provided when decrypting"
+ )
ctx = self._backend.create_symmetric_decryption_ctx(
self.algorithm, self.mode
)
- return self._wrap_ctx(ctx, False)
+ return self._wrap_ctx(ctx, encrypt=False)
def _wrap_ctx(self, ctx, encrypt):
if isinstance(self.mode, interfaces.ModeWithAuthenticationTag):
if encrypt:
- if self.mode.tag is not None:
- raise ValueError(
- "Authentication tag must be None when encrypting"
- )
return _AEADEncryptionContext(ctx)
else:
- if self.mode.tag is None:
- raise ValueError(
- "Authentication tag must be provided when decrypting"
- )
return _AEADCipherContext(ctx)
else:
return _CipherContext(ctx)