aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2013-11-07 13:03:39 -0800
committerDavid Reid <dreid@dreid.org>2013-11-07 13:03:39 -0800
commit30722b9a84ea38f70a22fbca13d8b3a6078af50a (patch)
tree540ea29d297e3f5d0c8ad171dc41118ca38ef4a1 /cryptography
parenta0b59223025a54c800c7844568428992f876a711 (diff)
downloadcryptography-30722b9a84ea38f70a22fbca13d8b3a6078af50a.tar.gz
cryptography-30722b9a84ea38f70a22fbca13d8b3a6078af50a.tar.bz2
cryptography-30722b9a84ea38f70a22fbca13d8b3a6078af50a.zip
Add a new Mode interface to document mode.name and start on some prose docs for interfaces.
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/primitives/ciphers/modes.py5
-rw-r--r--cryptography/hazmat/primitives/interfaces.py8
2 files changed, 13 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/modes.py b/cryptography/hazmat/primitives/ciphers/modes.py
index a60e8a34..e54872a6 100644
--- a/cryptography/hazmat/primitives/ciphers/modes.py
+++ b/cryptography/hazmat/primitives/ciphers/modes.py
@@ -16,6 +16,7 @@ from __future__ import absolute_import, division, print_function
from cryptography.hazmat.primitives import interfaces
+@interfaces.register(interfaces.Mode)
@interfaces.register(interfaces.ModeWithInitializationVector)
class CBC(object):
name = "CBC"
@@ -25,10 +26,12 @@ class CBC(object):
self.initialization_vector = initialization_vector
+@interfaces.register(interfaces.Mode)
class ECB(object):
name = "ECB"
+@interfaces.register(interfaces.Mode)
@interfaces.register(interfaces.ModeWithInitializationVector)
class OFB(object):
name = "OFB"
@@ -38,6 +41,7 @@ class OFB(object):
self.initialization_vector = initialization_vector
+@interfaces.register(interfaces.Mode)
@interfaces.register(interfaces.ModeWithInitializationVector)
class CFB(object):
name = "CFB"
@@ -47,6 +51,7 @@ class CFB(object):
self.initialization_vector = initialization_vector
+@interfaces.register(interfaces.Mode)
@interfaces.register(interfaces.ModeWithNonce)
class CTR(object):
name = "CTR"
diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py
index d3962a2a..d4466e72 100644
--- a/cryptography/hazmat/primitives/interfaces.py
+++ b/cryptography/hazmat/primitives/interfaces.py
@@ -25,6 +25,14 @@ def register(iface):
return register_decorator
+class Mode(six.with_metaclass(abc.ABCMeta)):
+ @abc.abstractproperty
+ def name(self):
+ """
+ A string naming this mode. (ex. ECB, CBC)
+ """
+
+
class ModeWithInitializationVector(six.with_metaclass(abc.ABCMeta)):
@abc.abstractproperty
def initialization_vector(self):