aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat
diff options
context:
space:
mode:
Diffstat (limited to 'cryptography/hazmat')
-rw-r--r--cryptography/hazmat/bindings/openssl/backend.py6
-rw-r--r--cryptography/hazmat/primitives/block/base.py56
-rw-r--r--cryptography/hazmat/primitives/ciphers/__init__.py (renamed from cryptography/hazmat/primitives/block/__init__.py)4
-rw-r--r--cryptography/hazmat/primitives/ciphers/algorithms.py (renamed from cryptography/hazmat/primitives/block/ciphers.py)42
-rw-r--r--cryptography/hazmat/primitives/ciphers/modes.py (renamed from cryptography/hazmat/primitives/block/modes.py)0
5 files changed, 48 insertions, 60 deletions
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py
index ea1073b9..18388783 100644
--- a/cryptography/hazmat/bindings/openssl/backend.py
+++ b/cryptography/hazmat/bindings/openssl/backend.py
@@ -20,10 +20,12 @@ import cffi
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.primitives import interfaces
-from cryptography.hazmat.primitives.block.ciphers import (
+from cryptography.hazmat.primitives.ciphers.algorithms import (
AES, Blowfish, Camellia, CAST5, TripleDES,
)
-from cryptography.hazmat.primitives.block.modes import CBC, CTR, ECB, OFB, CFB
+from cryptography.hazmat.primitives.ciphers.modes import (
+ CBC, CTR, ECB, OFB, CFB
+)
class Backend(object):
diff --git a/cryptography/hazmat/primitives/block/base.py b/cryptography/hazmat/primitives/block/base.py
deleted file mode 100644
index ece3b32d..00000000
--- a/cryptography/hazmat/primitives/block/base.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# 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 BlockCipher(object):
- def __init__(self, cipher, mode, backend=None):
- super(BlockCipher, self).__init__()
-
- if backend is None:
- from cryptography.hazmat.bindings import (
- _default_backend as backend,
- )
-
- self.cipher = cipher
- self.mode = mode
- self._backend = backend
-
- def encryptor(self):
- return _CipherContext(
- self._backend.ciphers.create_encrypt_ctx(self.cipher, self.mode))
-
- def decryptor(self):
- return _CipherContext(
- self._backend.ciphers.create_decrypt_ctx(self.cipher, 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
diff --git a/cryptography/hazmat/primitives/block/__init__.py b/cryptography/hazmat/primitives/ciphers/__init__.py
index 5b8942b6..0e81de35 100644
--- a/cryptography/hazmat/primitives/block/__init__.py
+++ b/cryptography/hazmat/primitives/ciphers/__init__.py
@@ -13,9 +13,9 @@
from __future__ import absolute_import, division, print_function
-from cryptography.hazmat.primitives.block.base import BlockCipher
+from cryptography.hazmat.primitives.ciphers.algorithms import Cipher
__all__ = [
- "BlockCipher",
+ "Cipher",
]
diff --git a/cryptography/hazmat/primitives/block/ciphers.py b/cryptography/hazmat/primitives/ciphers/algorithms.py
index 8046bd26..0b11e466 100644
--- a/cryptography/hazmat/primitives/block/ciphers.py
+++ b/cryptography/hazmat/primitives/ciphers/algorithms.py
@@ -13,6 +13,48 @@
from __future__ import absolute_import, division, print_function
+from cryptography.hazmat.primitives import interfaces
+
+
+class Cipher(object):
+ def __init__(self, cipher, mode, backend=None):
+ super(Cipher, self).__init__()
+
+ if backend is None:
+ from cryptography.hazmat.bindings import (
+ _default_backend as backend,
+ )
+
+ self.cipher = cipher
+ self.mode = mode
+ self._backend = backend
+
+ def encryptor(self):
+ return _CipherContext(
+ self._backend.ciphers.create_encrypt_ctx(self.cipher, self.mode))
+
+ def decryptor(self):
+ return _CipherContext(
+ self._backend.ciphers.create_decrypt_ctx(self.cipher, 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/block/modes.py b/cryptography/hazmat/primitives/ciphers/modes.py
index a60e8a34..a60e8a34 100644
--- a/cryptography/hazmat/primitives/block/modes.py
+++ b/cryptography/hazmat/primitives/ciphers/modes.py