sshkey

package
v0.0.0-...-785270f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: CC0-1.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sshkey implements parsing of SSH keys (authorized-keys format) and filtering of options.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoKey is returned if parsing did not find a key.
	ErrNoKey = errors.New("no key found")
	// ErrMissingQuote is returned if a quoted option is lacking a closing quote.
	ErrMissingQuote = errors.New("missing quote")
	// ErrGarbage is returned if the key contains trailing garbage.
	ErrGarbage = errors.New("trailing garbage")
	// ErrInconsistentType is returned if the human-readable and the machine-readable key types do not match.
	ErrInconsistentType = errors.New("inconsistent key type")
	// ErrOption is returned if an option has a wrong format/value.
	ErrOption = errors.New("option wrong format")
	// ErrUnknownOption is returned when an unknown option is encountered.
	ErrUnknownOption = errors.New("unknown option")
	// ErrFormat is returned if formatting of values, especially expiry-time, is wrong.
	ErrFormat = errors.New("invalid format")
)

Functions

func ExpireTimeToString

func ExpireTimeToString(expireTime time.Time) string

ExpireTimeToString returns the formatted expiry-time or an empty string if expiry is zero.

Types

type BoolOption

type BoolOption bool

BoolOption is a bool.

func (BoolOption) String

func (boolOpt BoolOption) String() string

String returns a string representation of BoolOption.

type Key

type Key struct {
	Options     Options
	Key         ssh.PublicKey
	Comment     string
	NotAfter    time.Time
	Fingerprint string
}

Key is an annotaed SSH key.

func ParseKey

func ParseKey(s string) (key *Key, err error)

ParseKey parses an authorized-key formatted key.

func (Key) ApplyToString

func (key Key) ApplyToString(opts Options) string

ApplyToString applies opts to a key and returns the authorized-key formatted result.

type Option

type Option struct {
	Key   string
	Value OptionValue
}

Option is a single ssh-authorized-keys option.

type OptionValue

type OptionValue interface {
	String() string
}

OptionValue is the value an Option can take.

type Options

type Options []Option

Options is a list of Option.

func ParseOptions

func ParseOptions(s string) (options Options, err error)

ParseOptions parses options as if they are from an authorized-keys file, it does not fail on missing keys.

func (Options) Apply

func (options Options) Apply(fromKey Options) Options

Apply "options" to "fromKey" options and return the new list of Option. "options" is the authoritative filter that limits "fromKey" options.

func (Options) String

func (options Options) String() string

type StringOption

type StringOption string

StringOption is a string.

func (StringOption) String

func (StringOpt StringOption) String() string

String returns a string representation of StringOption.

Jump to

Keyboard shortcuts

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