edg

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const GCMTagSize = 16

GCMTagSize is the AES-GCM tag size.

View Source
const (
	// SaltChainFilename is the name of the salt chain file.
	SaltChainFilename = "SALTCHAIN"
)

Variables

This section is empty.

Functions

func DecryptOptions

func DecryptOptions(
	ciphertext []byte, fileNum base.FileNum, keyManager *KeyManager,
) ([]byte, error)

DecryptOptions decrypts the contents of an OPTIONS file.

func EncryptOptions

func EncryptOptions(
	serializedOpts []byte, fileNum base.DiskFileNum, keyManager *KeyManager,
) ([]byte, error)

EncryptOptions encrypts the contents of an OPTIONS file.

func GetCipher

func GetCipher(key []byte) (cipher.AEAD, error)

GetCipher returns an AES-GCM cipher for key.

func TestEnableRandomKey

func TestEnableRandomKey()

TestEnableRandomKey enables the use of a random key in case no key has been set. This reduces required changes to existing tests.

Types

type ApprovedWriter

type ApprovedWriter struct {
	Writer interface {
		WriteApproved([]byte) (int, error)
	}
}

ApprovedWriter wraps an edg.Writer and provides an io.Writer interface. Use this to pass an edg.Writer to functions that expect an io.Writer.

func (*ApprovedWriter) Write

func (w *ApprovedWriter) Write(p []byte) (int, error)

type KeyManager

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

KeyManager manages the encryption keys for database files.

Call Create(fileNum) to create a new key when writing a file. Call Get(fileNum) to get the key when reading a file.

Internally, KeyManager maps file numbers to unique salts. File keys are derived with hkdf(masterKey, salt). The salts are stored integrity-protected in the SALTCHAIN file. The file is an append-only chain of saltBlocks, linked by HMACs.

As the encrypted files are file-level integrity-protected, together with key management via the salt chain we achieve "snapshot integrity" for the entire database.

func NewKeyManager

func NewKeyManager(fs vfs.FS, dirname string, masterKey []byte) (*KeyManager, error)

NewKeyManager creates a new KeyManager.

func (*KeyManager) Close

func (m *KeyManager) Close() error

Close closes the KeyManager.

func (*KeyManager) Create

func (m *KeyManager) Create(fileNum base.FileNum) ([]byte, error)

Create creates a new key for writing a file.

func (*KeyManager) Get

func (m *KeyManager) Get(fileNum base.FileNum) ([]byte, error)

Get gets the key for reading a file.

type Writer

type Writer interface {
	Write([]byte) (int, error)
	WriteApproved([]byte) (int, error)
}

Writer is an interface for Write and WriteApproved.

var Discard Writer = discard{}

Discard is a Writer on which all Write calls succeed without doing anything.

Jump to

Keyboard shortcuts

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