api

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 8 Imported by: 2

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

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

EncodeKey a key with an optional password.

Types

type Ext

type Ext map[string]interface{}

Extension

func (*Ext) Scan

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

func (Ext) Value

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

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

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

func (k *Key) Copy() *Key

Copy creates a copy of the key.

func (*Key) Created

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

Created marks the key as created with the specified time.

func (*Key) Equal

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

Equal returns true if 2 keys are equal.

func (*Key) ExtBool

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

func (*Key) ExtString

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

func (Key) HasLabel

func (k Key) HasLabel(label string) bool

HasLabel returns true if key has label.

func (*Key) IsEdX25519

func (k *Key) IsEdX25519() bool

IsEdX25519 returns true if EdX25519Key.

func (*Key) IsX25519

func (k *Key) IsX25519() bool

IsEdX25519 returns true if EdX25519Key.

func (*Key) SetExtBool

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

func (*Key) SetExtString

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

func (*Key) Updated

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

Updated marks the key as created with the specified time.

func (*Key) WithLabels

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

WithLabels returns key with labels added.

func (*Key) WithNotes

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

WithNotes sets notes on key.

type Labels

type Labels []string

Labels for key.

func (*Labels) Scan

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

Scan for sql.DB.

func (Labels) Value

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