encrypt

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package encrypt provides AES-256-GCM encryption middleware for Trove. It encrypts data on write and decrypts on read, using a KeyProvider interface for key management and rotation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encrypt

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

Encrypt provides AES-256-GCM encryption middleware.

func New

func New(opts ...Option) *Encrypt

New creates a new encryption middleware with the given options.

func (*Encrypt) Direction

func (e *Encrypt) Direction() middleware.Direction

Direction returns ReadWrite since encryption participates in both paths.

func (*Encrypt) Name

func (e *Encrypt) Name() string

Name returns the middleware identifier.

func (*Encrypt) WrapReader

func (e *Encrypt) WrapReader(ctx context.Context, r io.ReadCloser, _ *driver.ObjectInfo) (io.ReadCloser, error)

WrapReader wraps a reader to decrypt data from the driver.

func (*Encrypt) WrapWriter

func (e *Encrypt) WrapWriter(ctx context.Context, w io.WriteCloser, _ string) (io.WriteCloser, error)

WrapWriter wraps a writer to encrypt data before it reaches the driver. The encrypted format is: [12-byte nonce][encrypted data + GCM tag]. Since GCM requires knowing the full plaintext, this implementation buffers the data, encrypts, then writes. For large files, use chunked encryption at the stream level.

type KeyProvider

type KeyProvider interface {
	// Key returns the current encryption key (must be 32 bytes for AES-256).
	Key(ctx context.Context) ([]byte, error)
}

KeyProvider supplies encryption keys. Implementations can fetch keys from Vault, environment variables, or any other source.

type Option

type Option func(*Encrypt)

Option configures the Encrypt middleware.

func WithKeyProvider

func WithKeyProvider(kp KeyProvider) Option

WithKeyProvider sets the key provider.

type StaticKeyProvider

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

StaticKeyProvider is a KeyProvider that returns a fixed key.

func NewStaticKeyProvider

func NewStaticKeyProvider(key []byte) *StaticKeyProvider

NewStaticKeyProvider creates a key provider from a fixed 32-byte key.

func (*StaticKeyProvider) Key

func (p *StaticKeyProvider) Key(_ context.Context) ([]byte, error)

Key returns the static key.

Jump to

Keyboard shortcuts

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