Documentation
¶
Index ¶
Constants ¶
const (
// DefaultChunkSize is the plaintext size per chunk before encryption.
DefaultChunkSize = 64 * 1024
)
Variables ¶
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 ¶
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.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is the public streaming encryption writer.
func NewWriter ¶
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.