Пример #1
0
def recalc_encrypted_etag(ivs, warebox, cfg):
    """
    Encrypt all the files into the encrypted folder and return a list of etag

    @param ivs: a dictionary with pathname as key and ivs as value
    @param warebox: an instance of warebox class
    @param cfg: an instance of config class
    """
    encrypted_etags = dict()
    enc_dir = CryptoUtils.get_encryption_dir(cfg)
    encrypter = Encrypter(warebox)
    for pathname in ivs:
        pathname_operation = PathnameOperation(None, None, u'UPLOAD', pathname)
        pathname_operation.to_encrypt=True
        try:
            wrapped_task = TaskWrapper(pathname_operation)
            wrapped_task.prepare(cfg, enc_dir)
            wrapped_task.iv = unhexlify(ivs[pathname])
            encrypter._on_new_task(wrapped_task)
            while not encrypter._is_task_completed(wrapped_task):
                encrypter._task_step(wrapped_task)
            encrypter._on_task_complete(wrapped_task)
            encrypted_etags[pathname] = compute_md5_hex(wrapped_task.task.encrypted_pathname)
            clean_env(pathname_operation)
        except Exception:
            clean_env(pathname_operation)
            raise
    return encrypted_etags
Пример #2
0
def recalc_encrypted_etag(ivs, warebox, cfg, interruption=None):
    return recalc_encrypted_etag_in_mem(ivs, warebox, cfg, interruption)
    """
    Encrypt all the files into the encrypted folder and return a list of etag

    @param ivs: a dictionary with pathname as key and ivs as value
    @param warebox: an instance of warebox class
    @param cfg: an instance of config class
    """
    encrypted_etags = dict()
    enc_dir = CryptoUtils.get_encryption_dir(cfg)
    encrypter = Encrypter(warebox)
    for pathname in ivs:
        pathname_operation = PathnameOperation(None, None, u'UPLOAD', pathname)
        pathname_operation.to_encrypt = True
        try:
            wrapped_task = TaskWrapper(pathname_operation)
            wrapped_task.prepare(cfg, enc_dir)
            wrapped_task.iv = unhexlify(ivs[pathname])
            encrypter._on_new_task(wrapped_task)
            while not encrypter._is_task_completed(wrapped_task):
                encrypter._task_step(wrapped_task)
            encrypter._on_task_complete(wrapped_task)
            encrypted_etags[pathname] = compute_md5_hex(
                wrapped_task.task.encrypted_pathname)
            clean_env(pathname_operation)
        except Exception:
            clean_env(pathname_operation)
            raise
    return encrypted_etags