figenc

[RADIOACTIVE] rsa and symmetric key encryption scripts and executables
git clone git://git.figbert.com/figenc.git
Log | Files | Refs | README

prompts.py (3134B)


      1 from tkinter import messagebox
      2 from random import choice
      3 from json import load
      4 from path import find_path
      5 
      6 def overwrite_prompt():
      7     """Opens a tkinter messagebox asking if the user wants to
      8     overwrite the previously generated keys detected in the provided
      9     savefolder. Returns `True` if the user clicks ok, `False` if they
     10     click cancel.
     11     """
     12     return messagebox.askokcancel(
     13         "Overwrite Warning",
     14         (
     15             "The directory selected contains previously generated keys."
     16             " If you choose to continue, these keys will be overwritten"
     17             " and any files encrypted using these keys will be lost forever."
     18             "\n\nContinue?"
     19         )
     20     )
     21 
     22 def password_error():
     23     """"Raise an error informing the user that the provided passwords
     24     do not match.
     25     """
     26     messagebox.showwarning(
     27         "Passwords Do Not Match",
     28         "The passwords provided do not match. Please try again."
     29     )
     30 
     31 def encrypted_keys():
     32     messagebox.showwarning(
     33         "Keys are Password Locked",
     34         (
     35             "The keys provided are encrypted, and require a password to "
     36             "function. Please attempt decryption again with a password."
     37         )
     38     )
     39 
     40 def file_access_error(broken_paths):
     41     """Raise an error informing the user that some files aren't
     42     accessible by figENC.
     43 
     44     Keyword arguments:
     45     broken_paths -- a string with newlines seperating filepaths
     46     """
     47     messagebox.showwarning(
     48         "Filepath Access Failure",
     49         (
     50             "figENC can't access some of the files provided:\n\n"
     51             "Broken Paths:\n%s"%broken_paths
     52         )
     53     )
     54 
     55 def key_dir_error(folder):
     56     """Raise an error informing the user that the key directory isn't
     57     accessible by figENC.
     58 
     59     Keyword arguments:
     60     folder -- a directory filepath string
     61     """
     62     messagebox.showwarning(
     63         "Directory Access Failure",
     64         (
     65             "The key directory provided cannot be accessed by figENC."
     66             " Please try again with a new directory.\n\nDirectory"
     67             " provided:\n%s"%folder
     68         )
     69     )
     70 
     71 def missing_keys(folder):
     72     """Raise an error informing the user that some keys are missing
     73     from the passed directory
     74 
     75     Keyword arguments:
     76     folder -- a directory filepath string
     77     """
     78     messagebox.showwarning(
     79         "Directory Missing Keys",
     80         (
     81             "The directory provided is missing keys critical to encrypting"
     82             " files. Please correct and try again.\n\nDirectory provided:"
     83             "\n%s"%folder
     84         )
     85     )
     86 
     87 def wrong_pass():
     88     messagebox.showwarning(
     89         "Incorrect Password",
     90         "The password provided is incorrect. Please try again."
     91     )
     92 
     93 def success(mode):
     94     """Inform the user of the processes succesful completion
     95     with a fun message/reference.
     96     """
     97     if "enc" in mode or "key" in mode:
     98         lst = "enc"
     99     else:
    100         lst = "dec"
    101     with open(find_path("cookie.json")) as cookie_file:
    102         fun_messages = load(cookie_file)
    103     messagebox.showinfo(
    104         "Success",
    105         "The operation was complete. %s"%choice(fun_messages[lst])
    106     )