blocks

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockAlreadyExists = errors.New("block already exists for chunk")

Functions

func GenerateKeyHex

func GenerateKeyHex() (string, error)

func LoadEncryptionKey

func LoadEncryptionKey() ([]byte, error)

Types

type AESGCMTransformer

type AESGCMTransformer struct {
	Key []byte
}

func (*AESGCMTransformer) Decode

func (t *AESGCMTransformer) Decode(_ context.Context, in DecodeInput) (data []byte, err error)

func (*AESGCMTransformer) Encode

type Codec

type Codec string
const (
	CodecPlain  Codec = "plain"
	CodecAESGCM Codec = "aes-gcm"
)

func LoadDefaultCodec

func LoadDefaultCodec() (Codec, error)

LoadDefaultCodec resolves codec from env with a secure default. Precedence: env (COLDKEEP_CODEC) -> default (aes-gcm).

func ParseCodec

func ParseCodec(value string) (Codec, error)

type DecodeInput

type DecodeInput struct {
	ChunkHash  string
	Descriptor Descriptor
	Payload    []byte
}

type Descriptor

type Descriptor struct {
	ID            int64
	ChunkID       int64
	Codec         Codec
	FormatVersion int
	PlaintextSize int64
	StoredSize    int64
	Nonce         []byte
	ContainerID   int64
	BlockOffset   int64
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

Descriptor represents how a chunk is physically stored in the system. It links logical chunk identity to its encoded representation in a container.

type EncodeInput

type EncodeInput struct {
	ChunkID   int64
	ChunkHash string
	Plaintext []byte
}

type EncodedBlock

type EncodedBlock struct {
	Descriptor Descriptor
	Payload    []byte
}

type PlainTransformer

type PlainTransformer struct{}

PlainTransformer stores chunks as-is without any transformation.

func (*PlainTransformer) Decode

func (t *PlainTransformer) Decode(_ context.Context, in DecodeInput) ([]byte, error)

No transformation needed for plain codec, just return the payload as-is. Phase 6 Step 8: Avoid unnecessary byte copies during restore - Decode returns payload directly without copying - Caller (restore.go) never mutates plaintext after verification - Direct return saves memory allocation and copy time per chunk

func (*PlainTransformer) Encode

type Repository

type Repository struct {
	DB *sql.DB
}

func (*Repository) GetByChunkHash

func (r *Repository) GetByChunkHash(ctx context.Context, chunkHash string) (*Descriptor, error)

func (*Repository) GetByChunkID

func (r *Repository) GetByChunkID(ctx context.Context, chunkID int64) (*Descriptor, error)

func (*Repository) Insert

func (r *Repository) Insert(ctx context.Context, tx *sql.Tx, d *Descriptor) error

type Transformer

type Transformer interface {
	Encode(ctx context.Context, in EncodeInput) (*EncodedBlock, error)
	Decode(ctx context.Context, in DecodeInput) ([]byte, error)
}

Transformer defines how a chunk is transformed into a stored block and how a stored block is transformed back into plaintext.

func GetBlockTransformer

func GetBlockTransformer(codec Codec) (Transformer, error)

get codec transformer from codec name

Jump to

Keyboard shortcuts

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