-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcallable.sh
98 lines (86 loc) · 2.66 KB
/
callable.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#################################################
# This is an alias for the help callable function
#################################################
Cipher__callable_main() {
Cipher__callable_help
}
##################################################
# Displays relavant information on how to use
# this module
##################################################
Cipher__callable_help() {
more "$Ash__ACTIVE_MODULE_DIRECTORY/HELP.txt"
}
##################################################
# This is an alias for the encrypt callable function
##################################################
Cipher__callable_e() {
Cipher__callable_encrypt "$@"
}
##################################################
# This function encrypts a single file with
# the aes-256-cbc cipher algorithm
#
# @param $1: The file to encrypt
##################################################
Cipher__callable_encrypt() {
# Check if file is passed
if [[ "$1" = "" ]]; then
Logger__error "No file passed"
return 1
fi
# Make sure it's a file or directory
if [[ ! -f "$1" && ! -d "$1" ]]; then
Logger__error "'$1' is not a file or directory"
return 1
fi
# Get password
local password=""
Logger__prompt "Enter encryption password: "; read -s password; echo
if [[ "$password" = "" ]]; then
Logger__error "Password must be non-empty"
return 1
fi
Logger__prompt "Confirm encryption password: "; read -s cpassword; echo
if [[ "$cpassword" != "$password" ]]; then
Logger__error "Passwords do not match"
return 1
fi
# Encrypt the file
Cipher__encrypt "$1" "$password" "$Ash__TRUE"
}
##################################################
# This is an alias for the decrypt callable function
##################################################
Cipher__callable_d() {
Cipher__callable_decrypt "$@"
}
##################################################
# This function decrypts a single file that has
# been encrypted with the aes-256-cbc cipher
# algorithm
#
# @param $1: The file to decrypt
##################################################
Cipher__callable_decrypt() {
# Check if file is passed
if [[ "$1" = "" ]]; then
Logger__error "No file passed"
return 1
fi
# Make sure it's a file
if [[ ! -f "$1" ]]; then
Logger__error "'$1' is not a file"
return 1
fi
# Get password
local password=""
Logger__prompt "Enter decryption password: "; read -s password; echo
if [[ "$password" = "" ]]; then
Logger__error "Password must be non-empty"
return 1
fi
# Decrypt
Cipher__decrypt "$1" "$password" "$Ash__TRUE"
}