File: gpgconf.go

package info (click to toggle)
golang-github-gopasspw-pinentry 0.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 96 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 562 bytes parent folder | download
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
package gpgconf

import (
	"bufio"
	"bytes"
	"os"
	"os/exec"
	"strings"
)

// Path returns the path to a GPG component
func Path(key string) (string, error) {
	buf := &bytes.Buffer{}
	cmd := exec.Command("gpgconf")
	cmd.Stdout = buf
	cmd.Stderr = os.Stderr

	if err := cmd.Run(); err != nil {
		return "", err
	}

	key = strings.TrimSpace(strings.ToLower(key))
	sc := bufio.NewScanner(buf)
	for sc.Scan() {
		p := strings.Split(strings.TrimSpace(sc.Text()), ":")
		if len(p) < 3 {
			continue
		}
		if key == p[0] {
			return p[2], nil
		}
	}

	return "", nil
}