Documentation
¶
Index ¶
- Constants
- type Attributes
- type Filter
- type FilterSpec
- type Option
- type Properties
- type SecureNoteReader
- type T
- type Type
- func (Type) EnumValues() map[string]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
Constants ¶
const MaxRegexpLength = 2048
MaxRegexpLength is the maximum allowed length in bytes for a regular expression pattern in a FilterSpec.
const SecureNoteDescription = "secure note"
SecureNoteDescription is the description attribute used by WriteSecureNote for the items that it creates. Secure notes created by the macOS Keychain Access application use the same description and are hence matched by Filter.SecureNotesOnly also.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
type Attributes struct {
Keychain Type `json:"keychain" yaml:"keychain"`
Service string `json:"service" yaml:"service"`
Account string `json:"account" yaml:"account"`
Label string `json:"label,omitempty" yaml:"label,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
AccessGroup string `json:"access_group,omitempty" yaml:"access_group,omitempty"`
// Accessibility names when the item's contents can be decrypted, eg.
// when-unlocked, as one of the values accepted by ParseAccessibility. It
// is recorded for items in the data-protection and iCloud keychains; an
// item in the file-based keychain, whose access is governed by an access
// control list rather than by this attribute, reports an empty value.
Accessibility string `json:"accessibility,omitempty" yaml:"accessibility,omitempty"`
Created time.Time `json:"created,omitzero" yaml:"created,omitempty"`
Modified time.Time `json:"modified,omitzero" yaml:"modified,omitempty"`
}
Attributes describes a single keychain item: the attributes that identify and describe it, but never its contents. Query never asks the keychain for item data and hence Attributes has no field to report it in.
func Query ¶
func Query(_ Type, _ Filter, _ ...Option) ([]Attributes, error)
Query returns the attributes of every item in the requested keychain(s) that matches filter, for all accounts.
func (Attributes) IsSecureNote ¶
func (a Attributes) IsSecureNote() bool
IsSecureNote returns true if the item's description identifies it as a secure note.
type Filter ¶
type Filter struct {
// Any matches an item if any one of its service, account, label,
// description or comment attributes matches.
Any *regexp.Regexp
Service *regexp.Regexp
Account *regexp.Regexp
Label *regexp.Regexp
Description *regexp.Regexp
Comment *regexp.Regexp
// SecureNotesOnly restricts the results to secure notes, ie. to items
// whose description is SecureNoteDescription.
SecureNotesOnly bool
}
Filter selects keychain items by matching regular expressions against their attributes. All of the criteria that are set must match, ie. they are and'ed together, and a zero Filter matches every item. The expressions are unanchored and case sensitive, use ^, $ and (?i) as required.
func (Filter) Matches ¶
func (f Filter) Matches(attrs Attributes) bool
Matches returns true if attrs satisfies every criterion set in the filter.
type FilterSpec ¶
type FilterSpec struct {
Any string `json:"any,omitempty" yaml:"any,omitempty"`
Service string `json:"service,omitempty" yaml:"service,omitempty"`
Account string `json:"account,omitempty" yaml:"account,omitempty"`
Label string `json:"label,omitempty" yaml:"label,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
SecureNotesOnly bool `json:"secure_notes_only,omitempty" yaml:"secure_notes_only,omitempty"`
}
FilterSpec is the uncompiled, and hence serializable, form of a Filter. A query that is serviced by an out-of-process keychain plugin is sent as a FilterSpec, the plugin compiling the expressions itself since a compiled Filter cannot cross a process boundary.
func (FilterSpec) Compile ¶
func (s FilterSpec) Compile() (Filter, error)
Compile compiles the spec's regular expressions into a Filter. An expression that cannot be compiled is reported as an error that names the attribute it applies to, ie. one of any, service, account, label, description or comment; the names are those of the spec's fields, lowercased, so that a caller whose flags are named after them can report the error against the offending flag.
type Properties ¶
type Properties struct {
Account string `json:"account,omitempty" yaml:"account,omitempty"`
Label string `json:"label,omitempty" yaml:"label,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Accessibility string `json:"accessibility,omitempty" yaml:"accessibility,omitempty"`
}
Properties are the attributes of a keychain item that SetProperties can change. An empty field leaves the attribute it names as it is; there is no way to clear an attribute, only to replace it.
Accessibility is named by one of the values that ParseAccessibility accepts. It applies only to items in the data-protection and iCloud keychains; an item in the file-based keychain has no such attribute, its access being governed by an access control list instead, and the keychain silently ignores an attempt to set one. SetProperties reports that as an error rather than appearing to have made a change that it has not.
func (Properties) Empty ¶
func (p Properties) Empty() bool
Empty returns true if no property is to be changed.
func (Properties) Validate ¶
func (p Properties) Validate(_ Type) error
Validate returns an error indicating that setting properties is not implemented on this platform.
type SecureNoteReader ¶
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 (T) Query ¶
func (T) Query(_ Filter) ([]Attributes, error)
Query returns the attributes of the items in the keychain that match filter.
func (T) SetProperties ¶
func (T) SetProperties(_ string, _ Properties) error
SetProperties returns an error indicating that setting properties is not implemented on this platform.
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 (Type) EnumValues ¶
EnumValues satisfies flags.EnumType[Type].