Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Add binary to error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Schulz <[email protected]>
  • Loading branch information
dominikschulz committed Mar 25, 2021
1 parent 68c0c89 commit 189fee7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ type Client struct {
cmd *exec.Cmd
in io.WriteCloser
out *bufio.Reader
bin string
}

// New creates a new pinentry client
func New() (*Client, error) {
cmd := exec.Command(GetBinary())
bin := GetBinary()
cmd := exec.Command(bin)
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
Expand All @@ -56,13 +58,14 @@ func New() (*Client, error) {
return nil, err
}
if !bytes.HasPrefix(banner, []byte("OK")) {
return nil, fmt.Errorf("wrong banner: %s", banner)
return nil, fmt.Errorf("wrong banner from %s: %q", bin, banner)
}

cl := &Client{
cmd: cmd,
in: stdin,
out: br,
bin: bin,
}

return cl, nil
Expand Down Expand Up @@ -93,7 +96,7 @@ func (c *Client) Set(key, value string) error {
}
line, _, _ := c.out.ReadLine()
if string(line) != "OK" {
return fmt.Errorf("error: %s", line)
return fmt.Errorf("error from %s: %q", c.bin, line)
}
return nil
}
Expand All @@ -106,7 +109,7 @@ func (c *Client) Option(value string) error {
}
line, _, _ := c.out.ReadLine()
if string(line) != "OK" {
return fmt.Errorf("error: %s", line)
return fmt.Errorf("error from %s: %q", c.bin, line)
}
return nil
}
Expand All @@ -132,7 +135,7 @@ func (c *Client) GetPin() ([]byte, error) {
}
// now there should be some data
if !bytes.HasPrefix(buf, []byte("D ")) {
return nil, fmt.Errorf("unexpected response: %s", buf)
return nil, fmt.Errorf("unexpected response from %s: %s", c.bin, buf)
}

pin := make([]byte, len(buf))
Expand All @@ -145,7 +148,7 @@ func (c *Client) GetPin() ([]byte, error) {
return nil, err
}
if !bytes.HasPrefix(ok, []byte("OK")) {
return nil, fmt.Errorf("unexpected response: %s", ok)
return nil, fmt.Errorf("unexpected response from %s: %s", c.bin, ok)
}
pin = pin[2:]

Expand Down

0 comments on commit 189fee7

Please sign in to comment.