diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-24 11:14:27 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-29 17:19:46 -0600 |
commit | 4664108ac1771b694f917b9ef70d358638371c04 (patch) | |
tree | c7f0062e19a48b0993b96ccc5e6d4d9354cd4d2d | |
parent | bc31fb22979df3f034ce286fab20da71be76fe58 (diff) | |
download | cryptography-4664108ac1771b694f917b9ef70d358638371c04.tar.gz cryptography-4664108ac1771b694f917b9ef70d358638371c04.tar.bz2 cryptography-4664108ac1771b694f917b9ef70d358638371c04.zip |
simplify code for wrapping ciphercontext/aeadciphercontext
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/base.py | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py index c8c4533b..3f6ca0fe 100644 --- a/cryptography/hazmat/primitives/ciphers/base.py +++ b/cryptography/hazmat/primitives/ciphers/base.py @@ -30,32 +30,22 @@ class Cipher(object): self._backend = backend def encryptor(self): - if isinstance(self.mode, interfaces.ModeWithAAD): - return _AEADCipherContext( - self._backend.create_symmetric_encryption_ctx( - self.algorithm, self.mode - ) - ) - else: - return _CipherContext( - self._backend.create_symmetric_encryption_ctx( - self.algorithm, self.mode - ) - ) + ctx = self._backend.create_symmetric_encryption_ctx( + self.algorithm, self.mode + ) + return self._wrap_ctx(ctx) def decryptor(self): + ctx = self._backend.create_symmetric_decryption_ctx( + self.algorithm, self.mode + ) + return self._wrap_ctx(ctx) + + def _wrap_ctx(self, ctx): if isinstance(self.mode, interfaces.ModeWithAAD): - return _AEADCipherContext( - self._backend.create_symmetric_decryption_ctx( - self.algorithm, self.mode - ) - ) + return _AEADCipherContext(ctx) else: - return _CipherContext( - self._backend.create_symmetric_decryption_ctx( - self.algorithm, self.mode - ) - ) + return _CipherContext(ctx) @utils.register_interface(interfaces.CipherContext) |