diff --git a/main.go b/main.go index af6e133..9054750 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,8 @@ func main() { if strings.HasPrefix(args[0], "/") { targetLocation := offline.EntryRoot + offline.PathSeparator + args[0][1:] if isFile, _ := offline.TargetIsFile(targetLocation, true); isFile { - // TODO decrypt and display the entry - fmt.Println("It's a file!") + // TODO properly display entry contents (with headers) + offline.DecryptGPG(targetLocation) } else { fmt.Println(offline.AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + offline.AnsiReset) } diff --git a/src/offline/gpg.go b/src/offline/gpg.go new file mode 100644 index 0000000..4ab5c89 --- /dev/null +++ b/src/offline/gpg.go @@ -0,0 +1,20 @@ +package offline + +import ( + "os/exec" + "strings" +) + +// TODO GPG support is a temporary feature - it will be replaced with a different encryption scheme in the future +// TODO These functions may continue to exist after that point, but consider them deprecated + +// 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() + outputSlice := strings.Split(string(output), "\n") + for i, lineData := range outputSlice { + outputSlice[i] = strings.TrimRight(lineData, " \t") // remove trailing whitespace + } + return outputSlice +}