Skip to content

Commit

Permalink
Merge pull request #111 from reaperhulk/abc-decorators
Browse files Browse the repository at this point in the history
change abstract base class registration to use a decorator in modes
  • Loading branch information
alex committed Oct 17, 2013
2 parents b8f6a36 + b03527f commit 7c1610a
Showing 1 changed file with 11 additions and 6 deletions.
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)

0 comments on commit 7c1610a

Please sign in to comment.