mirror of
https://github.com/gopasspw/gopass.git
synced 2026-10-05 15:37:15 +02:00
* Adding regression test Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * fixing recipient logic to honor subkeys Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * Revert "Adding regression test" This reverts commit fcb85c9d2ee4ce3b1d53f934338c6a33e18d7d9d. Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * adding comment about noop Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * Linting Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * Addressing review comments Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> * avoid noise debug logs Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com> --------- Signed-off-by: Yolan Romailler <AnomalRoil@users.noreply.github.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gopasspw/gopass/internal/backend/crypto/gpg"
|
|
"github.com/gopasspw/gopass/pkg/debug"
|
|
)
|
|
|
|
// ListIdentities returns a parsed list of GPG secret keys.
|
|
func (g *GPG) ListIdentities(ctx context.Context) ([]string, error) {
|
|
if g.privKeys == nil {
|
|
kl, err := g.listKeys(ctx, "secret")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
g.privKeys = kl
|
|
}
|
|
|
|
if gpg.IsAlwaysTrust(ctx) {
|
|
return g.privKeys.Recipients(), nil
|
|
}
|
|
|
|
return g.privKeys.UseableKeys(gpg.IsAlwaysTrust(ctx)).Recipients(), nil
|
|
}
|
|
|
|
// FindIdentities searches for the given private keys.
|
|
func (g *GPG) FindIdentities(ctx context.Context, search ...string) ([]string, error) {
|
|
kl, err := g.listKeys(ctx, "secret", search...)
|
|
if err != nil || kl == nil {
|
|
return nil, err
|
|
}
|
|
|
|
if gpg.IsAlwaysTrust(ctx) {
|
|
return kl.Recipients(), nil
|
|
}
|
|
|
|
return kl.UseableKeys(gpg.IsAlwaysTrust(ctx)).Recipients(), nil
|
|
}
|
|
|
|
func (g *GPG) findKey(ctx context.Context, id string) (gpg.Key, bool) {
|
|
debug.Log("finding key %q", id)
|
|
kl, _ := g.listKeys(ctx, "secret", id)
|
|
if len(kl) >= 1 {
|
|
return kl[0], true
|
|
}
|
|
|
|
kl, _ = g.listKeys(ctx, "public", id)
|
|
if len(kl) >= 1 {
|
|
return kl[0], true
|
|
}
|
|
|
|
return gpg.Key{
|
|
Fingerprint: id,
|
|
}, false
|
|
}
|