secrets

package
v1.14.7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Ident is the header of the deprecated Gopass MIME secret.
	Ident = "GOPASS-SECRET-1.0"
)

Variables

View Source
var ErrMultiKey = fmt.Errorf("multiple identical keys not supported")

ErrMultiKey is returned when a key is found multiple times.

View Source
var ErrNoYAML = fmt.Errorf("no YAML marker")

ErrNoYAML is returned when no YAML section is found.

View Source
var ErrNotSupported = fmt.Errorf("not supported")

ErrNotSupported is returned when a method is not supported.

Functions

func New

func New() gopass.Secret

New creates a new secret.

Types

type KV

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

KV is a secret that contains a password line (maybe empty), any number of lines of key-value pairs (defined as: contains a colon) and any number of free text lines. This is the default secret format gopass uses and encourages. It should be compatible with most other password store implementations and works well with our vanity features (e.g. accessing single entries in secret).

Format ------ Line | Description ---- | -----------

  0 | Password. Must contain the "password" or be empty. Can not be omitted.
1-n | Key-Value pairs, e.g. "key: value". Can be omitted but the secret
    | might get parsed as a "Plain" secret if zero key-value pairs are found.
n+1 | Body. Can contain any number of characters that will be parsed as
    | UTF-8 and appended to an internal string. Note: Technically this can
    | be any kind of binary data but we neither support nor test this with
    | non-text data. Also we do not intent do support any kind of streaming
    | access, i.e. this is not intended for huge files.

Example ------- Line | Content ---- | -------

0 | foobar
1 | hello: world
2 | gopass: secret
3 | Yo
4 | Hi

This would be parsed as a KV secret that contains:

  • password: "foobar"
  • key-value pairs:
  • "hello": "world"
  • "gopass": "secret"
  • body: "Yo\nHi"

func NewKV

func NewKV() *KV

NewKV creates a new KV secret.

func NewKVWithData

func NewKVWithData(pw string, kvps map[string][]string, body string, converted bool) *KV

NewKVWithData returns a new KV secret populated with data.

func ParseKV

func ParseKV(in []byte) (*KV, error)

ParseKV tries to parse a KV secret.

func (*KV) Add added in v1.12.0

func (k *KV) Add(key string, value any) error

Add appends data to a given key.

func (*KV) Body

func (k *KV) Body() string

Body returns the body.

func (*KV) Bytes

func (k *KV) Bytes() []byte

Bytes serializes.

func (*KV) Del

func (k *KV) Del(key string) bool

Del removes a given key and all of its values.

func (*KV) FromMime

func (k *KV) FromMime() bool

FromMime returns whether this secret was converted from a Mime secret of not.

func (*KV) Get

func (k *KV) Get(key string) (string, bool)

Get returns the first value of that key.

func (*KV) Keys

func (k *KV) Keys() []string

Keys returns all keys.

func (*KV) Password

func (k *KV) Password() string

Password returns the password.

func (*KV) SafeStr added in v1.12.5

func (k *KV) SafeStr() string

SafeStr always returnes "(elided)".

func (*KV) Set

func (k *KV) Set(key string, value any) error

Set writes a single key.

func (*KV) SetPassword

func (k *KV) SetPassword(p string)

SetPassword updates the password.

func (*KV) Values added in v1.12.0

func (k *KV) Values(key string) ([]string, bool)

Values returns all values for that key.

func (*KV) Write

func (k *KV) Write(buf []byte) (int, error)

Write appends the buffer to the secret's body.

type PermanentError

type PermanentError struct {
	Err error
}

PermanentError signal that parsing should not attempt other formats.

func (*PermanentError) Error

func (p *PermanentError) Error() string

type Plain

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

Plain is a fallback secret type that is used if none of the other secret parsers accept the input. This secret only contains a byte slice of the input data. We attempt to support retrieving and even writing the password by looking for the first line break. The body (everything after the first line break) can also be retrieved. Key-value operations are not supported.

DO NOT use this, if possible.

func ParsePlain

func ParsePlain(in []byte) *Plain

ParsePlain never fails and always returns a Plain secret.

func (*Plain) Add added in v1.12.0

func (p *Plain) Add(_ string, _ any) error

Add does nothing.

func (*Plain) Body

func (p *Plain) Body() string

Body contains everything but the first line.

func (*Plain) Bytes

func (p *Plain) Bytes() []byte

Bytes returns the complete secret.

func (*Plain) Del

func (p *Plain) Del(_ string) bool

Del does nothing.

func (*Plain) Get

func (p *Plain) Get(key string) (string, bool)

Get returns the empty string for Plain secrets.

func (*Plain) Getbuf

func (p *Plain) Getbuf() string

Getbuf returns everything execpt the first line.

func (*Plain) Keys

func (p *Plain) Keys() []string

Keys always returns nil.

func (*Plain) Password

func (p *Plain) Password() string

Password returns the first line.

func (*Plain) SafeStr added in v1.12.5

func (p *Plain) SafeStr() string

SafeStr always returnes "(elided)".

func (*Plain) Set

func (p *Plain) Set(_ string, _ any) error

Set does nothing.

func (*Plain) SetPassword

func (p *Plain) SetPassword(value string)

SetPassword updates the first line.

func (*Plain) Values added in v1.12.0

func (p *Plain) Values(key string) ([]string, bool)

Values returns the empty string for Plain secrets.

func (*Plain) Write

func (p *Plain) Write(buf []byte) (int, error)

Write appends to the internal buffer.

func (*Plain) WriteString

func (p *Plain) WriteString(in string)

WriteString append a string to the internal buffer.

type YAML

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

YAML is a gopass secret that contains a parsed YAML data structure. This is a legacy data type that is discouraged for new users as YAML is neither trivial nor intuitive for users manually editing secrets (e.g. unquoted phone numbers being parsed as octal and such).

Format ------ Line | Description

  0 | Password
1-n | Body
n+1 | Separator ("---")
n+2 | YAML content.

func ParseYAML

func ParseYAML(in []byte) (*YAML, error)

ParseYAML will try to parse a YAML secret.

func (*YAML) Add added in v1.12.0

func (y *YAML) Add(key string, value any) error

Add doesn't work since as per YAML specification keys must be unique.

func (*YAML) Body

func (y *YAML) Body() string

Body returns the body.

func (*YAML) Bytes

func (y *YAML) Bytes() []byte

Bytes serialized this secret.

func (*YAML) Del

func (y *YAML) Del(key string) bool

Del removes a single key.

func (*YAML) Get

func (y *YAML) Get(key string) (string, bool)

Get returns the first value of a single key.

func (*YAML) Keys

func (y *YAML) Keys() []string

Keys returns all keys.

func (*YAML) Password

func (y *YAML) Password() string

Password returns the password.

func (*YAML) SafeStr added in v1.12.5

func (y *YAML) SafeStr() string

SafeStr always returnes "(elided)".

func (*YAML) Set

func (y *YAML) Set(key string, value any) error

Set sets a key to a given value.

func (*YAML) SetPassword

func (y *YAML) SetPassword(v string)

SetPassword updates the password.

func (*YAML) Values added in v1.12.0

func (y *YAML) Values(key string) ([]string, bool)

Values returns Get since as per YAML specification keys must be unique.

func (*YAML) Write

func (y *YAML) Write(buf []byte) (int, error)

Write appends the buffer to the secret's body.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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