api

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 8 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 Ext added in v0.1.22

type Ext map[string]interface{}

Extension

func (*Ext) Scan added in v0.1.22

func (e *Ext) Scan(val interface{}) error

func (Ext) Value added in v0.1.22

func (e Ext) Value() (driver.Value, error)

type Key

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

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

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

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

	// Extension (json marshalled to db)
	Ext Ext `json:"ext,omitempty" msgpack:"ext,omitempty" db:"ext"`

	// Deleted flag
	Deleted bool `json:"del,omitempty" msgpack:"del,omitempty" db:"del"`
}

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) Equal added in v0.1.22

func (k *Key) Equal(o *Key) bool

Equal returns true if 2 keys are equal.

func (*Key) ExtBool added in v0.1.22

func (k *Key) ExtBool(key string) bool

func (*Key) ExtString added in v0.1.22

func (k *Key) ExtString(key string) string

func (Key) HasLabel added in v0.1.20

func (k Key) HasLabel(label string) bool

HasLabel returns true if key has label.

func (*Key) IsEdX25519 added in v0.1.21

func (k *Key) IsEdX25519() bool

IsEdX25519 returns true if EdX25519Key.

func (*Key) IsX25519 added in v0.1.21

func (k *Key) IsX25519() bool

IsEdX25519 returns true if EdX25519Key.

func (*Key) SetExtBool added in v0.1.22

func (k *Key) SetExtBool(key string, val bool)

func (*Key) SetExtString added in v0.1.22

func (k *Key) SetExtString(key string, val string)

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) WithLabels added in v0.1.21

func (k *Key) WithLabels(labels ...string) *Key

WithLabels returns key with labels added.

func (*Key) WithNotes added in v0.1.21

func (k *Key) WithNotes(notes string) *Key

WithNotes sets notes on key.

type Labels added in v0.1.21

type Labels []string

Labels for key.

func (*Labels) Scan added in v0.1.21

func (p *Labels) Scan(src interface{}) error

Scan for sql.DB.

func (Labels) Value added in v0.1.21

func (p Labels) Value() (driver.Value, error)

Value for sql.DB.

Jump to

Keyboard shortcuts

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