api

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 5 Imported by: 15

Documentation

Overview

Package api provides a standard key format for serialization to JSON or msgpack, and conversions to and from specific key types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeKey added in v0.1.20

func EncodeKey(key *Key, password string) (string, error)

EncodeKey a key with an optional password.

Types

type Key

type Key struct {
	ID   keys.ID `json:"id,omitempty" msgpack:"id,omitempty"`
	Type string  `json:"type,omitempty" msgpack:"type,omitempty"`

	Private []byte `json:"priv,omitempty" msgpack:"priv,omitempty"`
	Public  []byte `json:"pub,omitempty" msgpack:"pub,omitempty"`

	CreatedAt int64 `json:"cts,omitempty" msgpack:"cts,omitempty"`
	UpdatedAt int64 `json:"uts,omitempty" msgpack:"uts,omitempty"`

	// Optional fields
	Labels []string `json:"labels,omitempty" msgpack:"labels,omitempty"`
	Notes  string   `json:"notes,omitempty" msgpack:"notes,omitempty"`

	// Application specific fields
	Token string `json:"token,omitempty" msgpack:"token,omitempty"`
}

Key is a concrete type for the keys.Key interface, which can be serialized and converted to concrete key types like keys.EdX25519Key. It also includes additional fields and metadata.

func DecodeKey added in v0.1.20

func DecodeKey(msg string, password string) (*Key, error)

DecodeKey a key with an optional password.

func NewKey

func NewKey(k keys.Key) *Key

NewKey creates api.Key from keys.Key interface.

func ParseKey added in v0.1.20

func ParseKey(b []byte, password string) (*Key, error)

ParseKey tries to determine what key type and parses the key bytes.

func (*Key) As

func (k *Key) As() keys.Key

As returns key as concrete type.

func (*Key) AsEdX25519

func (k *Key) AsEdX25519() *keys.EdX25519Key

AsEdX25519 returns a *EdX25519Key. Returns nil if we can't resolve.

func (*Key) AsEdX25519Public

func (k *Key) AsEdX25519Public() *keys.EdX25519PublicKey

AsEdX25519Public returns a *EdX25519PublicKey. Returns nil if we can't resolve.

func (*Key) AsPublic

func (k *Key) AsPublic() keys.Key

AsPublic returns public key as concrete type.

func (*Key) AsRSA

func (k *Key) AsRSA() *keys.RSAKey

AsRSA returns a RSAKey. Returns nil if we can't resolve.

func (*Key) AsRSAPublic

func (k *Key) AsRSAPublic() *keys.RSAPublicKey

AsRSAPublic returns a RSAPublicKey. Returns nil if we can't resolve.

func (*Key) AsX25519

func (k *Key) AsX25519() *keys.X25519Key

AsX25519 returns a X25519Key. If key is a EdX25519Key, it's converted to a X25519Key. Returns nil if we can't resolve.

func (*Key) AsX25519Public

func (k *Key) AsX25519Public() *keys.X25519PublicKey

AsX25519Public returns a X25519PublicKey. Returns nil if we can't resolve.

func (*Key) Check

func (k *Key) Check() error

Check if key is valid (has valid ID and type).

func (*Key) Copy added in v0.1.20

func (k *Key) Copy() *Key

Copy creates a copy of the key.

func (*Key) Created added in v0.1.20

func (k *Key) Created(ts int64) *Key

Created marks the key as created with the specified time.

func (Key) HasLabel added in v0.1.20

func (k Key) HasLabel(label string) bool

HasLabel returns true if key has label.

func (*Key) Updated added in v0.1.20

func (k *Key) Updated(ts int64) *Key

Updated marks the key as created with the specified time.

func (*Key) WithLabel added in v0.1.20

func (k *Key) WithLabel(label string) *Key

WithLabel returns key with label added.

Jump to

Keyboard shortcuts

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