Yup, except I wouldn't bother with a `ModeWIthNoParameters` class, the
default can simply be "doesn't have a thing". Also no need for
`isubclass(model.__class__)`, you can use `isinstance(mode, ...)`.



On Tue, Sep 10, 2013 at 11:44 AM, Paul Kehrer <notifications@github.com>wrote:

> In cryptography/primitives/block/modes.py:
>
> > @@ -20,3 +20,13 @@ class CBC(object):
> >      def __init__(self, initialization_vector):
> >          super(CBC, self).__init__()
> >          self.initialization_vector = initialization_vector
> > +
> > +    def get_iv_or_nonce(self, api):
> > +        return self.initialization_vector
> > +
> > +
> > +class ECB(object):
> > +    name = "ECB"
> > +
> > +    def get_iv_or_nonce(self, api):
> > +        return api.get_iv_for_ecb()
>
> Okay, so you register the modes against the ABCs, then in
> create_block_cipher_context you pass the mode to a method that
> introspects them:
>
>     def _introspect(self, mode):
>         klass = mode.__class__
>         if issubclass(klass, abc_modes.ModeWithInitializationVector):
>             return mode.initialization_vector
>         elif issubclass(klass, abc_modes.ModeWithNonce):
>             return mode.nonce
>         elif issubclass(klass, abc_modes.ModeWithNoParameters):
>             return self._ffi.NULL
>         else:
>             raise NotImplementedError
>
> This would require api to import abc_modes though.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/alex/cryptography/pull/53/files#r6274675>
> .
>



-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084