def add_key(): # create_key(user_id, key, name): keys.create_key( user_id=request.user['user_id'], key=request.form['key'].strip(), name=request.form['key_name'].strip(), ) return redirect(url_for('list_keys'))
def test_return_str(self): assert isinstance(keys.create_key(8), str)
def test_key_correct_length(self, length): key = keys.create_key(length) assert len(key) == length
def test_key_valid_chars(self, len): alphanumeric = ascii_letters + digits key = keys.create_key(len) assert all(char in alphanumeric for char in key)
parser.add_argument( "-f", "--file", help="The file to ENCRYPT or DECRYPT.", type=str, required=True ) args = parser.parse_args() if __name__ == "__main__": if args.action.lower() == "encrypt": if args.key: # If an encryption key was provided encryption_key = load_key(args.key) encrypt_file(args.file, encryption_key) print(f"{args.file} has been encrypted") else: # If an encryption key was NOT provided new_key = create_key() encrypt_file(args.file, new_key) print(f"{args.file} has been encrypted") elif args.action.lower() == "decrypt": if args.key is None: # If an encryption key was NOT provided print( "Cannot DECRYPT a file without the key that encrypted it. Please pass the '-k' option." ) sys.exit(1) else: # If an encryption key was provided encryption_key = load_key(args.key) decrypted_file = decrypt_file(args.file, encryption_key) print(f"{args.file} has been decrypted!") else: