keychain

package
v0.23.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package keychain keeps keys in the OS keychain, as Keys in contract.md defines. Each entry uses the service nicely and the account named after the key's service, and each call has a time limit. Only internal/cli reaches it: a key reaches an extension only through grants.

Index

Constants

View Source
const Service = "nicely"

Service is the keychain service of every entry that Nicely stores.

Variables

View Source
var (
	InteractiveLimit = 60 * time.Second
	Limit            = 10 * time.Second
)

The time limit of each call: InteractiveLimit in interactive mode, where a human can answer an unlock prompt, and Limit otherwise. The test binary shortens both, so a scenario proves a limit without waiting.

View Source
var ErrNotFound = keyring.ErrNotFound

ErrNotFound is the error of a Backend whose entry does not exist.

View Source
var ErrUnavailable = errors.New("the keychain is unavailable")

ErrUnavailable means that the keychain did not answer a read in time, or refused it, so the command counts it unavailable for every later key.

View Source
var ErrWriteUnknown = errors.New("the keychain did not confirm the write")

ErrWriteUnknown means that a write failed or got no answer within its limit. Its effect is unknown, because the keychain may still store or remove the key after ncly answers.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Get(service, account string) (string, error)
	Set(service, account, key string) error
	Delete(service, account string) error
}

Backend stores the entries: the OS keychain in ncly, and a test keychain in the test binary alone. Get returns ErrNotFound for a missing entry.

type Keychain

type Keychain struct {
	// contains filtered or unexported fields
}

Keychain asks a backend for one command. Once a call finds the keychain unavailable, it asks nothing more, so a command that reads several keys waits for one limit at most.

func New

func New(b Backend, interactive bool) *Keychain

New returns the keychain of one command, with the limit of its mode.

func (*Keychain) Available

func (k *Keychain) Available(ctx context.Context) (bool, error)

Available asks the keychain once whether it answers, and reports whether it still counts as available. It returns the error of ctx when ctx ends before the keychain answers or its limit passes.

func (*Keychain) Read

func (k *Keychain) Read(ctx context.Context, account string) (string, bool, error)

Read returns the key of an account and whether the keychain holds one. It returns ErrUnavailable without asking once the keychain is unavailable, and the error of ctx when ctx ends first.

func (*Keychain) Remove

func (k *Keychain) Remove(ctx context.Context, account string) error

Remove deletes the entry of an account, as Store writes one. An entry that is already gone counts as removed.

func (*Keychain) Store

func (k *Keychain) Store(ctx context.Context, account, key string) error

Store writes the key of an account. It returns ErrWriteUnknown when the write fails or gets no answer within the limit, and the error of ctx when ctx ends first, whose effect stays unknown too.

type System

type System struct{}

System is the OS keychain, through go-keyring. On macOS, go-keyring starts /usr/bin/security itself, outside the program runner, as Programs that ncly runs in contract.md allows.

func (System) Delete

func (System) Delete(service, account string) error

func (System) Get

func (System) Get(service, account string) (string, error)

Get reads an entry. On macOS, security also finds no entry when no default keychain exists, such as under a HOME that holds none. A write would then fail or open a window. So Get refuses that read, and the keychain counts as unavailable, as Keys defines. See #359.

func (System) Set

func (System) Set(service, account, key string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL