simplify code for wrapping ciphercontext/aeadciphercontext
diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py
index c8c4533..3f6ca0f 100644
--- a/cryptography/hazmat/primitives/ciphers/base.py
+++ b/cryptography/hazmat/primitives/ciphers/base.py
@@ -30,32 +30,22 @@
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)