diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-06 16:00:08 +0800 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-06 16:00:08 +0800 |
commit | dd0b51b92d9bafe6aaacc2565ace0c591a493965 (patch) | |
tree | b9990c3b9fd6113d4e189eaedcc77aef680e5ff2 | |
parent | 051099ee7ea64b902fc9821f139d0a955bfe8bc4 (diff) | |
download | cryptography-dd0b51b92d9bafe6aaacc2565ace0c591a493965.tar.gz cryptography-dd0b51b92d9bafe6aaacc2565ace0c591a493965.tar.bz2 cryptography-dd0b51b92d9bafe6aaacc2565ace0c591a493965.zip |
re-add base.py
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/__init__.py | 2 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/algorithms.py | 44 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/base.py | 58 |
3 files changed, 59 insertions, 45 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/__init__.py b/cryptography/hazmat/primitives/ciphers/__init__.py index 0e81de35..e5a8ca52 100644 --- a/cryptography/hazmat/primitives/ciphers/__init__.py +++ b/cryptography/hazmat/primitives/ciphers/__init__.py @@ -13,7 +13,7 @@ from __future__ import absolute_import, division, print_function -from cryptography.hazmat.primitives.ciphers.algorithms import Cipher +from cryptography.hazmat.primitives.ciphers.base import Cipher __all__ = [ diff --git a/cryptography/hazmat/primitives/ciphers/algorithms.py b/cryptography/hazmat/primitives/ciphers/algorithms.py index 56dca216..8046bd26 100644 --- a/cryptography/hazmat/primitives/ciphers/algorithms.py +++ b/cryptography/hazmat/primitives/ciphers/algorithms.py @@ -13,50 +13,6 @@ from __future__ import absolute_import, division, print_function -from cryptography.hazmat.primitives import interfaces - - -class Cipher(object): - def __init__(self, algorithm, mode, backend=None): - super(Cipher, self).__init__() - - if backend is None: - from cryptography.hazmat.bindings import ( - _default_backend as backend, - ) - - self.algorithm = algorithm - self.mode = mode - self._backend = backend - - def encryptor(self): - return _CipherContext( - self._backend.ciphers.create_encrypt_ctx(self.algorithm, - self.mode)) - - def decryptor(self): - return _CipherContext( - self._backend.ciphers.create_decrypt_ctx(self.algorithm, - self.mode)) - - -@interfaces.register(interfaces.CipherContext) -class _CipherContext(object): - def __init__(self, ctx): - self._ctx = ctx - - def update(self, data): - if self._ctx is None: - raise ValueError("Context was already finalized") - return self._ctx.update(data) - - def finalize(self): - if self._ctx is None: - raise ValueError("Context was already finalized") - data = self._ctx.finalize() - self._ctx = None - return data - class AES(object): name = "AES" diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py new file mode 100644 index 00000000..1599308c --- /dev/null +++ b/cryptography/hazmat/primitives/ciphers/base.py @@ -0,0 +1,58 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function + +from cryptography.hazmat.primitives import interfaces + + +class Cipher(object): + def __init__(self, algorithm, mode, backend=None): + super(Cipher, self).__init__() + + if backend is None: + from cryptography.hazmat.bindings import ( + _default_backend as backend, + ) + + self.algorithm = algorithm + self.mode = mode + self._backend = backend + + def encryptor(self): + return _CipherContext( + self._backend.ciphers.create_encrypt_ctx(self.algorithm, + self.mode)) + + def decryptor(self): + return _CipherContext( + self._backend.ciphers.create_decrypt_ctx(self.algorithm, + self.mode)) + + +@interfaces.register(interfaces.CipherContext) +class _CipherContext(object): + def __init__(self, ctx): + self._ctx = ctx + + def update(self, data): + if self._ctx is None: + raise ValueError("Context was already finalized") + return self._ctx.update(data) + + def finalize(self): + if self._ctx is None: + raise ValueError("Context was already finalized") + data = self._ctx.finalize() + self._ctx = None + return data |