api

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 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 EncryptKey

func EncryptKey(key *Key, sender *keys.EdX25519Key, recipient keys.ID, armored bool) ([]byte, error)

EncryptKey creates encrypted key from a sender to a recipient.

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"`

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

	CreatedAt int64 `json:"cts,omitempty" msgpack:"cts,omitempty"`
	UpdatedAt int64 `json:"uts,omitempty" msgpack:"uts,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 DecryptKey

func DecryptKey(b []byte, kr saltpack.Keyring, armored bool) (*Key, *keys.EdX25519PublicKey, error)

DecryptKey decrypts a key from a sender.

func DecryptKeyWithPassword

func DecryptKeyWithPassword(s string, password string) (*Key, error)

DecryptKeyWithPassword decrypts a key using a password.

func NewKey

func NewKey(k keys.Key) *Key

NewKey creates api.Key from keys.Key interface.

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) EncryptWithPassword

func (k *Key) EncryptWithPassword(password string) (string, error)

EncryptWithPassword creates an encrypted key using a password.

Jump to

Keyboard shortcuts

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