keyring

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keyring provides a small, dependency-free secret store backed by the operating system's native credential tooling: the `security` keychain CLI on macOS and `secret-tool` (libsecret) on Linux. It stores a single secret string per (service, account). Windows and other platforms report unsupported.

It shells out to the OS tools rather than taking a third-party dependency. On both macOS and Linux the secret is passed over stdin, never the argument vector, so it is not exposed via the process list. On macOS the write goes through `security -i` (interactive mode), whose command parser is line-based with a fixed 4096-byte line buffer, so Set rejects secrets containing newlines or exceeding that budget rather than silently corrupting them; Linux's secret-tool has no such restriction. MaxSecretLen reports that budget so a caller holding a larger value can split it across entries instead of being turned away.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("keyring: no OS keyring backend on this platform")

ErrUnsupported is returned when no OS keyring backend is available for the current platform.

Functions

This section is empty.

Types

type Keyring

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

Keyring is an OS-native secret store.

func New

func New() *Keyring

New returns a Keyring for the current platform.

func (*Keyring) Available

func (k *Keyring) Available() bool

Available reports whether this platform has a supported keyring backend. The backing tool (`secret-tool` on Linux) must also be installed; a missing tool surfaces as an error from Get/Set/Delete.

func (*Keyring) Delete

func (k *Keyring) Delete(service, account string) (bool, error)

Delete removes the entry under (service, account), reporting whether one existed.

func (*Keyring) Get

func (k *Keyring) Get(service, account string) (string, bool, error)

Get returns the secret stored under (service, account). The bool is false when no entry exists (which is not an error).

func (*Keyring) MaxSecretLen

func (k *Keyring) MaxSecretLen(service, account string) (int, bool)

MaxSecretLen reports the largest secret, in bytes, that Set accepts under (service, account) on this platform. ok is false when the backend imposes no practical limit, which is the case for Linux's secret-tool: it reads the secret from stdin rather than a command line. On macOS the secret shares the `security -i` command line with the service and account, so the budget depends on both and a caller that splits an oversized value must size each part against the exact account name it will be stored under.

The budget assumes the secret needs no quote escaping. securityQuote only expands `\` and `"`, neither of which appears in base64 or hex, so a caller storing encoded data gets the exact figure.

func (*Keyring) Set

func (k *Keyring) Set(service, account, secret string) error

Set stores secret under (service, account), replacing any existing value.

Jump to

Keyboard shortcuts

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