keychain

package
v0.0.0-...-2070fa5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Package cloudeng.io/macos/keychain

import cloudeng.io/macos/keychain

Package keychain provides a simple interface for reading and writing secure notes to the macOS keychain.

Constants

AccessibleDefault, AccessibleWhenUnlocked, AccessibleAfterFirstUnlock, AccessibleAlways, AccessibleWhenPasscodeSetThisDeviceOnly, AccessibleWhenUnlockedThisDeviceOnly, AccessibleAfterFirstUnlockThisDeviceOnly, AccessibleAccessibleAlwaysThisDeviceOnly
AccessibleDefault = Accessibility(keychain.AccessibleDefault)
AccessibleWhenUnlocked = Accessibility(keychain.AccessibleWhenUnlocked)
AccessibleAfterFirstUnlock = Accessibility(keychain.AccessibleAfterFirstUnlock)
AccessibleAlways = Accessibility(keychain.AccessibleAlways)
AccessibleWhenPasscodeSetThisDeviceOnly = Accessibility(keychain.AccessibleWhenPasscodeSetThisDeviceOnly)
AccessibleWhenUnlockedThisDeviceOnly = Accessibility(keychain.AccessibleWhenUnlockedThisDeviceOnly)
AccessibleAfterFirstUnlockThisDeviceOnly = Accessibility(keychain.AccessibleAfterFirstUnlockThisDeviceOnly)
AccessibleAccessibleAlwaysThisDeviceOnly = Accessibility(keychain.AccessibleAccessibleAlwaysThisDeviceOnly)

Types

Type Accessibility
type Accessibility int

Accessibility is the items accessibility

Functions
func ParseAccessibility(s string) (Accessibility, error)

ParseAccessibility parses a string into an Accessibility.

Methods
func (Accessibility) EnumValues() map[string]Accessibility

EnumValues satisfies flags.EnumType[Accessibility].

func (a Accessibility) String() string
Type Option
type Option func(o *options)

Option represents an option for configuring a keychain.T

Functions
func WithAccessibility(v Accessibility) Option

WithAccessibility sets the accessibility option for a keychain.T.

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger for a keychain.T. The default is to use a logger that discards all logs.

func WithUpdateInPlace(v bool) Option

WithUpdateInPlace sets the updateInPlace option for a keychain.T.

func WithWriteType(write Type) Option

WithWriteType sets the read and write types for a keychain.T. The default is to use the type specified when a keychain.T is created for both reading and writing.

Type SecureNoteReader
type SecureNoteReader interface {
	ReadSecureNote(service string) (data []byte, err error)
}

SecureNoteReader defines the interface for reading secure notes from the keychain.

Functions
func NewReadonly(typ Type, account string, opts ...Option) SecureNoteReader

NewReadonly creates a new readonly Keychain.

Type T
type T struct {
	// contains filtered or unexported fields
}

T represents a keychain that can be used to read and write secure notes.

Functions
func New(typ Type, account string, opts ...Option) *T

New creates a new Keychain.

Methods
func (kc T) DeleteSecureNote(service string) error

DeleteSecureNote deletes a secure note from the keychain.

func (kc T) ReadFile(service string) ([]byte, error)
func (kc T) ReadFileCtx(_ context.Context, service string) ([]byte, error)
func (kc T) ReadSecureNote(service string) (data []byte, err error)

ReadSecureNote reads a secure note from the keychain.

func (kc T) UpdateSecureNote(service string, data []byte) error

UpdateSecureNote updates an existing secure note in the keychain.

func (kc T) WriteFile(service string, data []byte, _ fs.FileMode) error
func (kc T) WriteFileCtx(_ context.Context, service string, data []byte, _ fs.FileMode) error
func (kc T) WriteSecureNote(service string, data []byte) error

WriteSecureNote writes a secure note to the keychain. It will update an existing note if WithUpdateInPlace was set to true.

Type Type
type Type int

Type represents the type of keychain to use, it maps to the underlying system keychain types but also includes the pseudotype 'all' which can be used, only when reading, to specify all keychains.

Constants
KeychainFileBased, KeychainDataProtectionLocal, KeychainICloud, KeychainAll
// KeychainFileBased represents the file-based keychain.
// This is the legacy, local only, file based keychain.
KeychainFileBased Type = iota
// KeychainDataProtectionLocal represents the data protection
// keychain which is local, but integrated with the system's secure
// enclave. Applications that use must be signed and have
// appropriate entitlements.
KeychainDataProtectionLocal
// KeychainICloud represents the iCloud keychain that can be synced
// across devices.
// Applications that use must be signed and have appropriate
// entitlements.
KeychainICloud
// KeychainAll represents any keychain type, it can only be used for
// reading and indicates that all keychains will be searched for
// the requested item.
KeychainAll

Functions
func ParseType(s string) (Type, error)

ParseType parses a string into a KeychainType.

Methods
func (Type) EnumValues() map[string]Type

EnumValues satisfies flags.EnumType[Type].

func (t Type) MarshalJSON() ([]byte, error)
func (t Type) MarshalText() ([]byte, error)
func (t Type) MarshalYAML() (any, error)
func (t Type) String() string
func (t *Type) UnmarshalJSON(data []byte) error
func (t *Type) UnmarshalText(text []byte) error
func (t *Type) UnmarshalYAML(node *yaml.Node) error
Type WriteType
type WriteType int

WriteType is like Type, except that it does not allow the value 'all'.

Methods
func (WriteType) EnumValues() map[string]WriteType

EnumValues satisfies flags.EnumType[WriteType].

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(o *options)

Option represents an option for configuring a keychain.T

type SecureNoteReader

type SecureNoteReader interface {
	ReadSecureNote(service string) (data []byte, err error)
}

SecureNoteReader defines the interface for reading secure notes from the keychain.

func NewReadonly

func NewReadonly(typ Type, account string, opts ...Option) SecureNoteReader

NewReadonly creates a new readonly Keychain.

type T

type T struct{}

func New

func New(typ Type, account string, opts ...Option) *T

New creates a new Keychain.

func (T) ReadSecureNote

func (u T) ReadSecureNote(service string) ([]byte, error)

func (T) UpdateSecureNote

func (u T) UpdateSecureNote(service string, data []byte) error

func (T) WriteSecureNote

func (u T) WriteSecureNote(service, account string, data []byte) error

type Type

type Type int

Type represents the type of keychain to use, it maps to the underlying system keychain types but also includes the pseudotype 'all' which can be used, only when reading, to specify all keychains.

const (
	// KeychainFileBased represents the file-based keychain.
	// This is the legacy, local only, file based keychain.
	KeychainFileBased Type = iota
	// KeychainDataProtectionLocal represents the data protection
	// keychain which is local, but integrated with the system's secure
	// enclave. Applications that use must be signed and have
	// appropriate entitlements.
	KeychainDataProtectionLocal
	// KeychainICloud represents the iCloud keychain that can be synced
	// across devices.
	// Applications that use must be signed and have appropriate
	// entitlements.
	KeychainICloud
	// KeychainAll represents any keychain type, it can only be used for
	// reading and indicates that all keychains will be searched for
	// the requested item.
	KeychainAll
)

func ParseType

func ParseType(s string) (Type, error)

ParseType parses a string into a KeychainType.

func (Type) EnumValues

func (Type) EnumValues() map[string]Type

EnumValues satisfies flags.EnumType[Type].

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) MarshalText

func (t Type) MarshalText() ([]byte, error)

func (Type) MarshalYAML

func (t Type) MarshalYAML() (any, error)

func (Type) String

func (t Type) String() string

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) error

func (*Type) UnmarshalText

func (t *Type) UnmarshalText(text []byte) error

func (*Type) UnmarshalYAML

func (t *Type) UnmarshalYAML(node *yaml.Node) error

type WriteType

type WriteType int

WriteType is like Type, except that it does not allow the value 'all'.

func (WriteType) EnumValues

func (WriteType) EnumValues() map[string]WriteType

EnumValues satisfies flags.EnumType[WriteType].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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