def call_decrypt(self, filepath: str, session: Session = None) -> str: ''' Override DownloadJob. Decrypt the file located at the given filepath and store its plaintext content in the local database. The file containing the plaintext should be deleted once the content is stored in the db. The return value is an empty string; messages have no original filename. ''' with NamedTemporaryFile('w+') as plaintext_file: try: self.gpg.decrypt_submission_or_reply(filepath, plaintext_file.name, is_doc=False) set_message_or_reply_content(model_type=Message, uuid=self.uuid, session=session, content=plaintext_file.read()) finally: # clean up directory where decryption happened try: os.rmdir(os.path.dirname(filepath)) except Exception as e: logger.warning( "Error deleting decryption directory of message %s: %s", self.uuid, e) return ""
def call_decrypt(self, filepath: str, session: Session = None) -> str: """ Override DownloadJob. Decrypt the file located at the given filepath and store its plaintext content in the local database. The file containing the plaintext should be deleted once the content is stored in the db. The return value is an empty string; messages have no original filename. """ with NamedTemporaryFile("w+") as plaintext_file: try: self.gpg.decrypt_submission_or_reply(filepath, plaintext_file.name, is_doc=False) set_message_or_reply_content( model_type=Message, uuid=self.uuid, session=session, content=plaintext_file.read(), ) finally: try: os.rmdir(os.path.dirname(filepath)) except OSError: msg = f"Could not delete decryption directory: {os.path.dirname(filepath)}" logger.debug(msg) return ""
def call_decrypt(self, filepath: str, session: Session = None) -> str: ''' Override DownloadJob. Decrypt the file located at the given filepath and store its plaintext content in the local database. The file containing the plaintext should be deleted once the content is stored in the db. The return value is an empty string; messages have no original filename. ''' with NamedTemporaryFile('w+') as plaintext_file: self.gpg.decrypt_submission_or_reply(filepath, plaintext_file.name, is_doc=False) set_message_or_reply_content( model_type=Message, uuid=self.uuid, session=session, content=plaintext_file.read()) return ""
def test_set_message_decryption_status_with_content_with_content( session, source): """ It should be possible to set the decryption status of an object in the database to `True`. Additionally, if `content` is passed in, the `content` column of the DB should take that value. This is to ensure that we have a way to decrypt something without violating the condition: if is_decrypted then content is not none. """ message = factory.Message(source=source["source"], is_downloaded=True, is_decrypted=None, content=None) session.add(message) session.commit() set_message_or_reply_content(type(message), message.uuid, "mock_content", session) mark_as_decrypted(type(message), message.uuid, session) # requery to ensure new object message = session.query(db.Message).get(message.id) assert message.is_decrypted is True assert message.content == "mock_content"