gopass/pkg/pinentry/cli/fallback.go
google-labs-jules[bot] 86720090b6
docs: Add GoDoc to pkg and improve markdown files (#3251)
This change adds GoDoc comments to many of the public symbols in the
`pkg/` directory. It also includes various improvements to the
documentation in `README.md` and other markdown files in the `docs/`
directory.

This is a partial documentation effort, as requested by the user, to
get a pull request submitted quickly.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2025-09-22 19:37:15 +02:00

53 lines
1.2 KiB
Go

// Package cli provides a pinentry client that uses the terminal
// for input and output. It is a drop-in replacement for the
// pinentry program. It is used to ask for a passphrase or PIN
// in the terminal.
package cli
import (
"context"
"fmt"
"github.com/gopasspw/gopass/pkg/termio"
)
// Client is a pinentry CLI drop-in.
type Client struct {
repeat bool
}
// New creates a new client.
func New() *Client {
return &Client{repeat: false}
}
// Set is a no-op unless you're requesting a repeat.
func (c *Client) Set(key string) error {
if key == "REPEAT" {
c.repeat = true
}
return nil
}
// Option is a no-op.
func (c *Client) Option(string) error {
return nil
}
// GetPINContext prompts for the pin in the terminal and returns the output.
// The context is only used for tests.
func (c *Client) GetPINContext(ctx context.Context) (string, error) {
pw, err := termio.AskForPassword(ctx, "your PIN", c.repeat)
if err != nil {
return "", fmt.Errorf("failed to ask for PIN: %w", err)
}
return pw, nil
}
// GetPIN prompts for the pin in the terminal and returns the output.
func (c *Client) GetPIN() (string, error) {
return c.GetPINContext(context.TODO())
}