secret

package
v0.0.0-...-3301e3d Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrMsgInvalidSimpleFmt is returned when trying to decode
	// a simple-format secret that is not simple-encoded
	ErrMsgInvalidSimpleFmt = "bad format"

	// ErrMsgCouldNotDecodePEM is returned when trying to decode
	// a PEM-format secret that is not PEM encoded
	ErrMsgCouldNotDecodePEM = "could not decode pem block"
)
View Source
const (
	// ErrMsgEmptyValue is returned when the user attempts
	// to create a shard with no data provided
	ErrMsgEmptyValue = "shard can not have empty value"

	// ErrMsgCouldNotEncrypt is returned when an error occurs
	// while attempting to encrypt a shard
	ErrMsgCouldNotEncrypt = "could not encrypt shard value"

	// ErrMsgCouldNotDecrypt is returned when an error occurs
	// while attempting to decrypt a shard
	ErrMsgCouldNotDecrypt = "could not decrypt shard value"

	// ErrMsgIncorrectDecryptionKey is returned when the user attempts to
	// decrypt an EncryptedShard with the wrong key (key id mismatch)
	ErrMsgIncorrectDecryptionKey = "the provided key does not match the shard's encryption key's fingerprint"

	// ErrMsgCouldNotDecode is returned when a shard value could not
	// be base64 encoded
	ErrMsgCouldNotDecode = "could not b64 decode shard value"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EncryptedShard

type EncryptedShard struct {
	Value string `json:"value"`
	KeyID string `json:"key_id"`
}

EncryptedShard represents a shard that has been encrypted

func (*EncryptedShard) Decrypt

func (es *EncryptedShard) Decrypt(k *rsa.PrivateKey) (*Shard, error)

Decrypt removes the ASCII armour off a shard and decrypts its value

type Secret

type Secret struct {
	Shards []*EncryptedShard
}

Secret represents an encrypted secret

func DecodePEM

func DecodePEM(s string) (*Secret, error)

DecodePEM returns an encrypted secret from a pem block

func DecodeSimpleSecret

func DecodeSimpleSecret(s string) (*Secret, error)

DecodeSimpleSecret returns a sharded representation of the encrypted secret

func (*Secret) EncodePEM

func (s *Secret) EncodePEM() (string, error)

EncodePEM returns an encrypted secret in a PEM block

func (*Secret) EncodeSimple

func (s *Secret) EncodeSimple() string

EncodeSimple returns a simple string representation of the encrypted secret. This format is KEY_ID(VALUE)

type Shard

type Shard struct {
	Value []byte
}

Shard describes a piece of secret that has been split with Shamir's Secret Sharing Algorithm

func NewShard

func NewShard(value []byte) (*Shard, error)

NewShard returns a populated Shard struct

func (*Shard) Encrypt

func (s *Shard) Encrypt(k *rsa.PublicKey) (*EncryptedShard, error)

Encrypt encrypts and ASCII armours a shard's value

Jump to

Keyboard shortcuts

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