Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change abstract base class registration to use a decorator in modes #111

Merged
merged 1 commit into from
Oct 17, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions cryptography/primitives/block/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
from cryptography.primitives import interfaces


def register(iface):
def register_decorator(klass):
iface.register(klass)
return klass
return register_decorator


@register(interfaces.ModeWithInitializationVector)
class CBC(object):
name = "CBC"

Expand All @@ -28,6 +36,7 @@ class ECB(object):
name = "ECB"


@register(interfaces.ModeWithInitializationVector)
class OFB(object):
name = "OFB"

Expand All @@ -36,6 +45,7 @@ def __init__(self, initialization_vector):
self.initialization_vector = initialization_vector


@register(interfaces.ModeWithInitializationVector)
class CFB(object):
name = "CFB"

Expand All @@ -44,15 +54,10 @@ def __init__(self, initialization_vector):
self.initialization_vector = initialization_vector


@register(interfaces.ModeWithNonce)
class CTR(object):
name = "CTR"

def __init__(self, nonce):
super(CTR, self).__init__()
self.nonce = nonce


interfaces.ModeWithInitializationVector.register(CBC)
interfaces.ModeWithInitializationVector.register(OFB)
interfaces.ModeWithInitializationVector.register(CFB)
interfaces.ModeWithNonce.register(CTR)