local

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package local provides an in-memory AES-256-GCM encryption provider for testing. It stores master keys in memory and supports key revocation for crypto-shredding simulation.

This provider should NOT be used in production. Use the kms or vault providers instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider) error

Option configures a local Provider.

func WithKey

func WithKey(keyID string, key []byte) Option

WithKey pre-loads a master key into the provider. The key must be exactly 32 bytes (AES-256).

WithKey is normally applied at construction time via New, but it mirrors the guards of AddKey so it remains safe if applied to an already-constructed or closed provider: it takes the write lock, rejects use after Close, and initializes the key map if it has not been allocated yet.

type Provider

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

Provider is an in-memory AES-256-GCM encryption provider for testing. Keys are stored in memory and never persisted.

func New

func New(opts ...Option) (*Provider, error)

New creates a new local encryption provider.

func (*Provider) AddKey

func (p *Provider) AddKey(keyID string, key []byte) error

AddKey adds a master key to the provider. The key must be exactly 32 bytes (AES-256).

func (*Provider) Close

func (p *Provider) Close() error

Close releases all key material.

func (*Provider) Decrypt

func (p *Provider) Decrypt(_ context.Context, keyID string, ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext using AES-256-GCM with the specified master key.

func (*Provider) DecryptDataKey

func (p *Provider) DecryptDataKey(_ context.Context, keyID string, encryptedKey []byte) ([]byte, error)

DecryptDataKey decrypts a previously encrypted DEK using the master key.

func (*Provider) Encrypt

func (p *Provider) Encrypt(_ context.Context, keyID string, plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM with the specified master key.

func (*Provider) GenerateDataKey

func (p *Provider) GenerateDataKey(_ context.Context, keyID string) (*encryption.DataKey, error)

GenerateDataKey creates a new random 32-byte DEK and encrypts it with the master key.

func (*Provider) IsRevoked added in v1.1.3

func (p *Provider) IsRevoked(keyID string) (bool, error)

IsRevoked reports whether keyID has been revoked — soft or hard. It implements encryption.Revocable. Callers that need to distinguish a still-recoverable soft-revocation from a permanent shred use RevocationState.

func (*Provider) RevocationState added in v1.1.3

func (p *Provider) RevocationState(keyID string) (encryption.RevocationState, error)

RevocationState reports keyID's fine-grained revocation state, first promoting an elapsed soft-revocation to a permanent shred. Implements encryption.StatefulRevocable.

func (*Provider) RevokeKey

func (p *Provider) RevokeKey(keyID string) error

RevokeKey marks a key as revoked and removes the key material. This simulates crypto-shredding: once revoked, data encrypted with this key can never be decrypted. It implements encryption.Revocable and is idempotent — revoking an already-revoked key is a no-op success.

func (*Provider) SoftRevokeKey added in v1.1.3

func (p *Provider) SoftRevokeKey(keyID string, graceWindow time.Duration) error

SoftRevokeKey blocks decryption under keyID but allows UnrevokeKey to restore it until graceWindow elapses, after which it is permanent. Implements encryption.RecoverableRevocable.

func (*Provider) UnrevokeKey added in v1.1.3

func (p *Provider) UnrevokeKey(keyID string) error

UnrevokeKey restores a soft-revoked key if still within its grace window. Implements encryption.RecoverableRevocable.

Jump to

Keyboard shortcuts

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