Handle errors resulting from failed decryption

This commit is contained in:
2024-03-03 22:15:35 -05:00
parent 0f65cd31cb
commit 207a4762b6
+7 -1
View File
@@ -1,6 +1,8 @@
package offline
import (
"fmt"
"os"
"os/exec"
"strings"
)
@@ -11,7 +13,11 @@ import (
// DecryptGPG decrypts a GPG-encrypted file and returns the contents as a slice of (trimmed) strings
func DecryptGPG(targetLocation string) []string {
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")
for i, lineData := range outputSlice {
outputSlice[i] = strings.TrimRight(lineData, " \t") // remove trailing whitespace