stream

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 10 Imported by: ? 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 (

	// DefaultChunkSize is the plaintext size per chunk before encryption.
	DefaultChunkSize = 64 * 1024
)

Variables

View Source
var ErrClosed = errors.New("stream: use of closed Writer or Reader")

ErrClosed is returned when Write, Read, or Close is called on an already-closed Writer or Reader.

Functions

This section is empty.

Types

type DataKey

type DataKey struct {
	Plaintext  []byte // raw AES key (16/24/32 bytes)
	WrappedKey []byte // opaque ciphertext for header; nil for direct AES
}

DataKey holds a plaintext AES key and its wrapped (encrypted) form. For direct AES (staticKeyProvider), WrappedKey is nil. For Vault envelope encryption, WrappedKey is the Vault-encrypted data key.

type KeyProvider

type KeyProvider interface {
	GenerateKey() (*DataKey, error)
	UnwrapKey(wrappedKey []byte) ([]byte, error)
}

KeyProvider generates and unwraps per-file data encryption keys.

func NewStaticKeyProvider

func NewStaticKeyProvider(key []byte) KeyProvider

NewStaticKeyProvider returns a KeyProvider that always uses the given AES key.

type Option

type Option func(*options)

Option configures streaming encryption behavior.

func WithChunkSize

func WithChunkSize(size int) Option

WithChunkSize sets the plaintext chunk size (default 64KB).

func WithCompression

func WithCompression() Option

WithCompression enables gzip compression before encryption.

type Reader

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

Reader is the public streaming decryption reader.

func NewReader

func NewReader(src io.Reader, kp KeyProvider) (*Reader, error)

NewReader returns a streaming decryption reader. It reads the CRFS header, unwraps the data key, and returns a reader that decrypts and decompresses on Read. The caller must call Close on the returned Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the reader and the underlying source (if it implements io.Closer).

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

type Writer

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

Writer is the public streaming encryption writer.

func NewWriter

func NewWriter(dst io.Writer, kp KeyProvider, opts ...Option) (*Writer, error)

NewWriter returns a streaming encryption writer. Data written to the returned Writer is compressed (if configured), encrypted in chunks, and written to dst. The caller must call Close on the returned Writer to finalize the stream.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes all buffered data and writes the end marker. The caller is responsible for closing the underlying io.Writer.

func (*Writer) Write

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

Jump to

Keyboard shortcuts

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