def decrypt(pathname_operation, warebox, cfg, logger=None): """ Decrypts a file @param pathname_operation: an instance of pathname_operation class @param warebox: an instance of warebox class @cfg an instance of cfg class @logger optional logger object """ try: tw = TaskWrapper(pathname_operation) enc_dir = CryptoUtils.get_encryption_dir(cfg) tw.prepare(cfg, enc_dir) if logger: logger.debug(u'Decrypting file %s to %s' % (tw.task.encrypted_pathname, tw.task.temp_pathname)) decrypter = Decrypter(warebox) decrypter._on_new_task(tw) while not decrypter._is_task_completed(tw): decrypter._task_step(tw) decrypter._on_task_complete(tw) except Exception as e: if logger: logger.exception(u'Decryption task fail on %s' % pathname_operation.pathname) on_decrypt_fail(pathname_operation, e, logger) raise
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
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