mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-05 08:37:20 -04:00
Handle errors resulting from failed decryption
This commit is contained in:
+7
-1
@@ -1,6 +1,8 @@
|
|||||||
package offline
|
package offline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -11,7 +13,11 @@ import (
|
|||||||
// DecryptGPG decrypts a GPG-encrypted file and returns the contents as a slice of (trimmed) strings
|
// DecryptGPG decrypts a GPG-encrypted file and returns the contents as a slice of (trimmed) strings
|
||||||
func DecryptGPG(targetLocation string) []string {
|
func DecryptGPG(targetLocation string) []string {
|
||||||
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
||||||
output, _ := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Failed to decrypt \"" + targetLocation + "\" - ensure it is a valid GPG-encrypted file and that you entered your passphrase correctly" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
outputSlice := strings.Split(string(output), "\n")
|
outputSlice := strings.Split(string(output), "\n")
|
||||||
for i, lineData := range outputSlice {
|
for i, lineData := range outputSlice {
|
||||||
outputSlice[i] = strings.TrimRight(lineData, " \t") // remove trailing whitespace
|
outputSlice[i] = strings.TrimRight(lineData, " \t") // remove trailing whitespace
|
||||||
|
|||||||
Reference in New Issue
Block a user