diff --git a/pass/pass_linux.go b/pass/pass_linux.go index 3ab6081..d9bace9 100644 --- a/pass/pass_linux.go +++ b/pass/pass_linux.go @@ -5,6 +5,7 @@ package pass import ( + "bytes" "encoding/base64" "errors" "fmt" @@ -32,6 +33,13 @@ type Pass struct{} var initializationMutex sync.Mutex var passInitialized bool +// CheckInitialized checks whether the password helper can be used. It +// internally caches and so may be safely called multiple times with no impact +// on performance, though the first call may take longer. +func (p Pass) CheckInitialized() bool { + return p.checkInitialized() == nil +} + func (p Pass) checkInitialized() error { initializationMutex.Lock() defer initializationMutex.Unlock() @@ -70,8 +78,9 @@ func (p Pass) runPass(stdinContent string, args ...string) (string, error) { } func (p Pass) runPassHelper(stdinContent string, args ...string) (string, error) { + var stdout, stderr bytes.Buffer cmd := exec.Command("pass", args...) - cmd.Stdin = strings.NewReader(stdin) + cmd.Stdin = strings.NewReader(stdinContent) cmd.Stdout = &stdout cmd.Stderr = &stderr