lnencrypt

package
v0.15.10001 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encrypter

type Encrypter struct {
	// contains filtered or unexported fields
}

Encrypter is a struct responsible for encrypting and decrypting data.

func KeyRingEncrypter

func KeyRingEncrypter(keyRing keychain.KeyRing) (*Encrypter, error)

KeyRingEncrypter derives an encryption key to encrypt all our files that are written to disk and returns an Encrypter object holding the key.

The key itself, is the sha2 of a base key that we get from the keyring. We derive the key this way as we don't force the HSM (or any future abstractions) to be able to derive and know of the cipher that we'll use within our protocol.

func (Encrypter) DecryptPayloadFromReader

func (e Encrypter) DecryptPayloadFromReader(payload io.Reader) ([]byte,
	error)

DecryptPayloadFromReader attempts to decrypt the encrypted bytes within the passed io.Reader instance using the key derived from the passed keyRing. For further details regarding the key derivation protocol, see the KeyRingEncrypter function.

func (Encrypter) EncryptPayloadToWriter

func (e Encrypter) EncryptPayloadToWriter(payload []byte,
	w io.Writer) error

EncryptPayloadToWriter attempts to write the set of provided bytes into the passed io.Writer in an encrypted form. We use a 24-byte chachapoly AEAD instance with a randomized nonce that's pre-pended to the final payload and used as associated data in the AEAD.

type EncrypterDecrypter

type EncrypterDecrypter interface {
	// EncryptPayloadToWriter attempts to write the set of provided bytes
	// into the passed io.Writer in an encrypted form.
	EncryptPayloadToWriter([]byte, io.Writer) error

	// DecryptPayloadFromReader attempts to decrypt the encrypted bytes
	// within the passed io.Reader instance using the key derived from
	// the passed keyRing.
	DecryptPayloadFromReader(io.Reader) ([]byte, error)
}

EncrypterDecrypter is an interface representing an object that encrypts or decrypts data.

type MockKeyRing

type MockKeyRing struct {
	Fail bool
}

func (*MockKeyRing) DeriveKey

func (m *MockKeyRing) DeriveKey(
	keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)

func (*MockKeyRing) DeriveNextKey

func (m *MockKeyRing) DeriveNextKey(
	keyFam keychain.KeyFamily) (keychain.KeyDescriptor, error)

Jump to

Keyboard shortcuts

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