Did I find the right examples for you? yes no

All Samples(10)  |  Call(7)  |  Derive(0)  |  Import(3)
return a suitable cipher object to decrypt/encrypt the archive
using the certificate key and input parameters (iv, etc).

        def get_cipher(archive, cert):
    """ return a suitable cipher object to decrypt/encrypt the archive
        using the certificate key and input parameters (iv, etc).
    """
    input = None
    key = None
    cipher = archive.meta.cipher
    if hasattr(cipher, 'input'):
        input = cipher.input
    if hasattr(cert, 'key'):
        key = cert.key
    elif hasattr(cert, 'keys') and len(cert.keys) > 0:
        if hasattr(cipher, 'key'):
            idx = cipher.key
            if idx > 0 and idx <= len(cert.keys):
                key = cert.keys[idx-1]
        else:
            key = cert.keys[0]
    mode = None
    if hasattr(cipher, 'mode'):
        mode = cipher.mode
    elif isinstance(cipher, str):
        mode = cipher
    if mode:
        cipher_class = cipher_modes().get(mode)
        if cipher_class:
            return cipher_class(key, input)
        


src/l/a/lacore-0.1.3/lacore/dumper/__init__.py   lacore(Download)
from lacore.adf.elements import Certificate, Archive, Meta, Cipher
from lacore.exceptions import InvalidArchiveError
from lacore.cipher import get_cipher
from lacore.crypt import CryptIO
from abc import ABCMeta, abstractmethod
        with self:
            with StreamSource(self.end(), self.uploader(), self.chunk) as dest:
                cipher = get_cipher(self.docs['archive'], self.docs['cert'])
                with CryptIO(dest, cipher, hashobj=self.hashobj) as fdst:
                    for result in self.archive(items, fdst, cb):
                        yield result
 
    def dedump(self, infile, chunk=1024):
        cipher = get_cipher(self.docs['archive'], self.docs['cert'])

src/l/a/lacore-0.1.3/lacore/archive/__init__.py   lacore(Download)
from tempfile import NamedTemporaryFile
from lacore.crypt import CryptIO
from lacore.cipher import get_cipher
from shutil import copyfileobj
from zipfile import ZipFile
from abc import ABCMeta, abstractmethod
 
 
def restore_archive(archive, path, cert, folder, tmpdir, cb=None):
    cipher = get_cipher(archive, cert)

src/l/a/lacore-0.1.3/lacore/t/test_cipher.py   lacore(Download)
    def test_get_cipher(self):
        from lacore.adf.elements import Archive, Meta, Cipher
        from lacore.cipher import get_cipher
        with patch('lacore.cipher.xor.CipherXOR.__init__') as xorinit:
            xorinit.return_value = None
            archive = Archive('foo', Meta('zip', Cipher('xor', 1, 'bar')))
            get_cipher(archive, Mock(key='baz'))
            cert = Mock(keys=['baz'])
            del cert.key
            get_cipher(archive, cert)
            xorinit.assert_called_with('baz', 'bar')
            archive = Archive('foo', Meta('zip', Cipher('xor', 2, 'bar')))
            cert.keys.append('spam')
            get_cipher(archive, cert)
            archive = Archive('foo', Meta('zip', 'xor'))
            get_cipher(archive, cert)