def file_decrypt( blockchain_id, hostname, sender_blockchain_id, sender_key_id, input_path, output_path, passphrase=None, config_path=CONFIG_PATH, wallet_keys=None ):
config_dir = os.path.dirname(config_path)<EOL>decrypted = False<EOL>old_key = False<EOL>old_key_index = <NUM_LIT:0><EOL>sender_old_key_index = <NUM_LIT:0><EOL>sender_key_info = file_key_lookup( sender_blockchain_id, None, None, key_id=sender_key_id, config_path=config_path, wallet_keys=wallet_keys ) <EOL>if '<STR_LIT:error>' in sender_key_info:<EOL><INDENT>log.error("<STR_LIT>" % sender_key_info['<STR_LIT:error>'])<EOL>return {'<STR_LIT:error>': '<STR_LIT>'}<EOL><DEDENT>if '<STR_LIT>' in list(sender_key_info.keys()):<EOL><INDENT>old_key = True<EOL>sender_old_key_index = sender_key_info['<STR_LIT>']<EOL><DEDENT>key_info = file_key_lookup( blockchain_id, <NUM_LIT:0>, hostname, config_path=config_path, wallet_keys=wallet_keys )<EOL>if '<STR_LIT:error>' not in key_info:<EOL><INDENT>res = file_decrypt_from_key_info( sender_key_info, blockchain_id, <NUM_LIT:0>, hostname, input_path, output_path, passphrase=passphrase, config_path=config_path, wallet_keys=wallet_keys )<EOL>if '<STR_LIT:error>' in res:<EOL><INDENT>if not res['<STR_LIT:status>']:<EOL><INDENT>log.error("<STR_LIT>" % res['<STR_LIT:error>'])<EOL>return {'<STR_LIT:error>': '<STR_LIT>'}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>decrypted = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.error("<STR_LIT>" % key_info['<STR_LIT:error>'])<EOL><DEDENT>if not decrypted:<EOL><INDENT>for i in range(<NUM_LIT:1>, MAX_EXPIRED_KEYS):<EOL><INDENT>res = file_decrypt_from_key_info( sender_key_info, blockchain_id, i, hostname, input_path, output_path, passphrase=passphrase, config_path=config_path, wallet_keys=wallet_keys )<EOL>if '<STR_LIT:error>' in res:<EOL><INDENT>log.error("<STR_LIT>" % res['<STR_LIT:error>'])<EOL>return {'<STR_LIT:error>': '<STR_LIT>'}<EOL><DEDENT>else:<EOL><INDENT>decrypted = True<EOL>old_key = True<EOL>old_key_index = i<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if decrypted:<EOL><INDENT>log.debug("<STR_LIT>" % (blockchain_id, hostname))<EOL>ret = {'<STR_LIT:status>': True}<EOL>if old_key:<EOL><INDENT>ret['<STR_LIT>'] = "<STR_LIT>"<EOL>ret['<STR_LIT>'] = old_key_index<EOL>ret['<STR_LIT>'] = sender_old_key_index<EOL><DEDENT>return ret<EOL><DEDENT>else:<EOL><INDENT>return {'<STR_LIT:error>': '<STR_LIT>'}<EOL><DEDENT>
Decrypt a file from a sender's blockchain ID.
Try our current key, and then the old keys
(but warn if there are revoked keys)
Return {'status': True} on success, and write plaintext to output_path
Return {'error': ...} on failure