Skip to main content

Module library

Module library 

Source

Re-exports§

pub use paths::tmp_path;

Structs§

BlobVerdict
The server’s key-free per-blob verdict.
CustodyReceipt
A custody receipt: a CustodyReceiptCore plus its hybrid attestation signature.
CustodyReceiptCore
The signed core of a CustodyReceipt — every field the server attestation key covers.
EvictionReport
What an eviction sweep reclaimed.
GateKeeper
Tracks per-view fresh-auth grants and enforces the grace window (SR1). Owns no authentication itself: it drives a LocalAuthGate to mint grants and then gates the sensitive view reads.
Library
An open, locked Capsule library.
PinnedKeys
The pinned history a run verifies under, and how it got there.
ReceiptExpectations
What the client sent to the server, checked against the receipt’s server-recomputed facts: a server that took custody of different bytes cannot answer with a matching receipt.
ReleaseGate
The verify-before-destroy gate over a StorageVerifier. It never destroys anything itself: may_release is the pure decision the three destructive paths (device-owned-original release, Move-import source deletion, streaming-mode release) consult before any local cleanup, and streaming import drives its per-asset release window through the same call.
StorageAttestation
A signed storage attestation: a [StorageAttestationCore] plus its hybrid signature.
StorageVerdict
The per-asset verdict from POST /storage/verify. durable attests this home server’s storage only — never replicas or peers.
SystemGraceClock
The production GraceClock: a monotonic Instant anchored at construction. Monotonic (not wall-clock) so a user or NTP nudging the system clock can neither extend nor prematurely expire a grant.
ViewGuard
A short-lived proof that a live grant existed for view at the moment it was minted. Consumed immediately by a gated read; it carries no capability of its own beyond naming the view.

Enums§

AttestationStoreError
Errors reading or persisting an asset’s attestation log.
BlobRole
A blob’s role within an asset, as the storage-verification endpoint reports it.
GateError
Refusal returned by the gate’s grant surface.
GatedQueryError
Failure of a gated view query — either the gate refused, or the underlying index read failed.
GatedView
A view that requires fresh local auth before it opens (SR1). A grant is per-view: authenticating for one view never opens the other.
KeyPinError
Errors pinning or reading a server’s attestation-key history.
KeyPinOutcome
What pinning a fetched history did.
KeyPinRestoreOutcome
What folding a backup’s pinned histories into this library did.
LibraryError
LocalAuthError
Failure surfaced by a LocalAuthGate backend.
ReceiptRejection
Why a fetched receipt was rejected — every variant refuses release.
ReceiptStoreError
Errors persisting a receipt beside the provenance chain.
ReleaseDecision
The gate’s decision. Release is returned only when all three checks pass (durable verdict, matching per-blob detail + verify_asset, and a verified receipt).
RetainReason
Why the gate refused to release. Every variant retains the local bytes.
ThumbnailSize
VerifierError
A transport error fetching a verdict or receipt from the server. A gate that cannot reach a definitive durable/receipt answer never destroys — the caller retains and retries.

Constants§

DEFAULT_GRACE
The default per-view grace window (SR1): one fresh grant covers 5 minutes, after which the view re-locks and re-authentication is required.

Traits§

GraceClock
A monotonic clock for the grace window, injectable so tests drive time deterministically. Only differences between readings are meaningful; the absolute value has no meaning.
LocalAuthGate
The per-platform local-authentication seam, implemented by native code (Swift/Kotlin) behind the capsule_core_ffi namespace’s LocalAuthGate foreign-trait mirror; a plain Rust trait here. Rust calls into it to perform the fresh-auth challenge; core never sees the biometric or the credential.
StorageVerifier
The client’s source of the server-side facts the gate needs: the key-free /storage/verify verdict and whether a verified custody receipt is held for the write. The capsule-sdk fills this over HTTP (POST /storage/verify + GET …/receipt verified under the pinned attestation key); tests fill it with deterministic mocks. Sync by construction — the offline data plane calls it; async callers resolve the futures before invoking the gate.

Functions§

append_attestation
Append a verified attestation (cbor, its bytes as received) to the log of asset.
append_receipt
Append a verified receipt to the asset’s on-disk log ({uuid}.receipts.cbor), idempotent on receipt_seq: re-persisting a receipt already present is a no-op, so a retried fetch never duplicates the log. The log is stored as canonical CBOR of the receipt Vec in chain order.
attestation_key_pins_path
.library/attestation-keys.cbor — the pinned attestation-key history of every server this library has contacted.
attestations_path
media/{YYYY}/{YYYY-MM}/{uuid}.attestations.cbor — the client’s signed storage-attestation log for the asset, kept beside its custody receipts (SSoT: Transfer — Durability: Signed Storage Attestation). Evidence, not a cache: it is included verbatim in the backup artifact.
available_bytes
The library volume’s available bytes — a thin statvfs / GetDiskFreeSpaceEx wrapper over the filesystem holding library_root.
cache_sweep
Reclaim cached representations until the reclaimable set fits within budget_bytes. Deletes each evicted representation’s cache file from disk and removes its index row. A cache file that is already gone is treated as reclaimed (not an error) and its stale row is still dropped. Pinned and device-owned originals are never evicted by this automatic path; canonical media/ files are never candidates (they are not tracked in cached_representations).
init_library
Create a new Capsule library at root with the given name.
largest_asset_fits
The pure minimum-headroom verdict for a streaming import: streaming bounds peak disk to the in-flight window, but a single asset must still fully materialize locally (original + derivatives + metadata) before its upload and release, so the largest single asset in the plan must fit within available space minus the headroom margin. When even one asset cannot fit, streaming cannot proceed and the plan surfaces a hard error rather than stall mid-stream — streaming cannot make a single file smaller than the disk.
load_attestation_log
Read the raw attestation log of an asset: each entry is one attestation’s canonical-CBOR bytes, as received. An absent file is an empty log.
load_attestations
Read and decode the attestation log of an asset, in the order the attestations were received. An absent file is an empty log.
load_pinned_attestation_keys
The history pinned for origin, or None when this library has never contacted it.
load_receipts
Read the persisted custody-receipt log for an asset. An absent file is an empty log (Ok).
media_dir
media/{YYYY}/{YYYY-MM}/
media_path
media/{YYYY}/{YYYY-MM}/{uuid}.{ext} where date comes from capture_utc
meta_cache_path
index/meta/{s1}/{s2}/{uuid}.meta.cbor
open_library
Open an existing Capsule library at root.
pin_attestation_keys
Check the history origin just published against the pin, pin or extend it, and return the pinned history every receipt from that server is verified under.
read_attestation_key_pins
The pin file’s bytes exactly as they are on disk, for the backup artifact to carry, or None when this library has pinned nothing.
rebuild_index
Rebuild the SQLite index from the sidecars on disk.
receipts_path
media/{YYYY}/{YYYY-MM}/{uuid}.receipts.cbor — the client’s custody-receipt log for the asset, appended beside the provenance chain (SSoT: Storage Verification — Custody Receipts). Evidentiary, not a cache: it is included verbatim in the backup artifact.
release_is_safe
The verify-before-destroy predicate: destructive local cleanup of irreplaceable bytes may proceed only when the server’s verdict is durable, every declared blob individually re-checks as safely stored (the client never trusts the server’s aggregate over the details it can recompute), and verify_asset accepted the asset.
release_move_source
Move-import source deletion. Deleting the external source after a Move-mode import waits on the server’s durable verdict + a verified receipt — never on the local library copy alone — so a crash mid-import cannot lose the only copy. Returns the decision; the source is unlinked only on Release. The gate alone: a caller holding the library uses Workspace::release_move_source, which adds the read-back hash check before it reaches here.
release_owned_original
Device-owned-original release (the cache-eviction sweep’s counterpart for owned originals, which cache_sweep never touches automatically). An original the device itself uploaded is the source of truth until the server durably holds it; it is released — its local file deleted and its owned-original representation row dropped, after which it becomes an ordinary server-only, re-fetchable asset — only on a Release decision. On any Retain the file and row are untouched.
restore_attestation_key_pins
Fold the pin file a backup carried into this library’s pin.
sidecar_path
media/{YYYY}/{YYYY-MM}/{uuid}.cbor
streaming_recommended
The pure streaming-recommendation predicate: streaming mode is recommended when the plan’s total size, plus a configurable headroom margin, meets or exceeds the volume’s available bytes. Attached to the plan at confirmation (never computed inside the pure planner).
thumbnail_path
index/thumbnails/{size}/{s1}/{s2}/{uuid}.{format} where format is “jxl” or “webp”
transcode_h264_path
index/transcodes/h264/{s1}/{s2}/{uuid}.mp4
transcode_live_path
index/transcodes/live/{s1}/{s2}/{uuid}.mov
trash_path
.library/trash/{uuid}.{ext}
uuid_shard
Returns the first two hex chars and next two hex chars of a UUID string (without hyphens).
verify_receipt
Verify a fetched receipt for a finalized upload: the hybrid signature under one of the pinned_keys (the published attestation-key history), then that the server’s recomputed facts match what the client sent, then the gross-drift bound on received_at.