chunk

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package chunk stores an arbitrary-size secret across several fixed-capacity credential blobs, hiding the Windows Credential Manager per-blob byte cap behind a header-plus-chunks layout. It is pure and store-agnostic — the caller injects a Store — so the split/join, the commit protocol, and the shrink cleanup are unit-tested on any OS without a real credential store.

Layout: a header blob under the base target records the chunk count and the total length; the payload lives in chunk blobs beside it. The header is written last, so it is the commit point — a crash before it leaves orphaned chunks that no header references, and a header pointing at a missing or short chunk reads back as "not found" rather than as a truncated secret.

Index

Constants

View Source
const DefaultMaxBlob = 2560

DefaultMaxBlob is the Windows Credential Manager CRED_MAX_CREDENTIAL_BLOB_SIZE: the most bytes a single credential blob can hold.

Variables

View Source
var ErrMissing = errors.New("chunk: target not found")

ErrMissing is what a Store's Get and Delete return for an absent target.

View Source
var ErrNotFound = errors.New("chunk: item not found")

ErrNotFound is returned by Get and Delete when no intact chunked item exists: an absent header, or a header that references a missing or short chunk.

Functions

This section is empty.

Types

type Chunker

type Chunker struct {
	Store   Store
	MaxBlob int
}

Chunker splits secrets across a Store's blobs. MaxBlob is the per-blob byte cap (DefaultMaxBlob when zero); tests set a small value to exercise the boundaries.

func (Chunker) Delete

func (c Chunker) Delete(service, account string) error

Delete removes the chunks and then the header. An absent item is ErrNotFound, which the caller maps to a no-op so Delete stays idempotent.

func (Chunker) Get

func (c Chunker) Get(service, account string) ([]byte, error)

Get reassembles the secret, returning ErrNotFound if the header is absent or references a chunk that is missing or shorter than the header promises.

func (Chunker) Set

func (c Chunker) Set(service, account string, secret []byte) error

Set writes secret as chunk blobs followed by the committing header, then removes any chunk tail left over from a larger previous value.

type Store

type Store interface {
	Get(target string) ([]byte, error)
	Set(target string, blob []byte) error
	Delete(target string) error
}

Store is the per-target blob store the chunker drives. A target is an opaque key; Get and Delete report an absent target with ErrMissing.

Jump to

Keyboard shortcuts

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