Skip to main content

DiskArtifactStore

Struct DiskArtifactStore 

Source
pub struct DiskArtifactStore { /* private fields */ }
Expand description

On-disk content-addressed signed artifact store.

Format on disk for a single blob:

magic(16) || version(4) || content_hash(32) || zstd(payload) || hmac_tag(32)

The HMAC covers everything except the trailing 32-byte tag itself. Verification uses constant-time comparison.

Implementations§

Source§

impl DiskArtifactStore

Source

pub fn new(dir: PathBuf, hmac_key: [u8; 32]) -> Self

Construct a disk store rooted at dir, signing with hmac_key. The directory is created lazily on the first put.

This wraps hmac_key in a SingleKeyProvider internally, so the store writes and reads under exactly that one key — identical to the historical single-key behaviour. Use Self::with_key_provider for rotation support.

Source

pub fn with_key_provider( dir: PathBuf, key_provider: Arc<dyn KeyProvider>, ) -> Self

Construct a disk store rooted at dir whose signing keys come from key_provider.

New puts sign under KeyProvider::active_key; get and list try every key in KeyProvider::read_keys, so a store built with a RotatingKeyProvider can read blobs written under a retired key after rotation. The directory is created lazily on the first put.

Source

pub fn put_with_metadata( &self, payload: &[u8], metadata: &ArtifactMetadata, ) -> Result<ContentHash, ArtifactError>

Insert payload (exactly like ArtifactStore::put) and write an ArtifactMetadata sidecar next to the blob under the active key.

The blob and the sidecar are independent files: the blob is the content-addressed envelope, the sidecar is a .meta.json serde document. A later Self::metadata reads the sidecar back. Plain put continues to write no sidecar, so metadata stays optional.

metadata.original_len is recorded as supplied by the caller (it is provenance, not a re-derived fact); pass payload.len() for the common “this is the blob I just stored” case.

Source

pub fn metadata( &self, hash: &ContentHash, ) -> Result<ArtifactMetadata, ArtifactError>

Read the ArtifactMetadata sidecar for hash under whichever accepted key (active or retired) the blob actually lives under.

Rotation-aware: this resolves the blob’s key with the same resolve_read_key probe get / list use, then reads the sidecar partitioned under that key’s fingerprint. A blob written under a now-retired key (and its sidecar) is therefore still readable here after rotation, matching what get exposes.

Returns ArtifactError::NotFound if no blob exists under any accepted key, or if the blob exists but carries no sidecar (e.g. it was written via plain put). A malformed sidecar surfaces as ArtifactError::Metadata.

Trait Implementations§

Source§

impl ArtifactStore for DiskArtifactStore

Source§

fn put(&self, payload: &[u8]) -> Result<ContentHash, ArtifactError>

Insert payload into the store. The returned ContentHash is blake3(payload); repeated calls with identical payloads return identical hashes and overwrite the existing entry in place.
Source§

fn get(&self, hash: &ContentHash) -> Result<Vec<u8>, ArtifactError>

Fetch the payload previously inserted under hash. Returns ArtifactError::NotFound on a genuine miss; integrity-failure variants (ArtifactError::BadMagic, ArtifactError::BadVersion, ArtifactError::BadHmac, ArtifactError::HashMismatch) are returned when a record was present but the format checks rejected it.
Source§

fn get_to( &self, hash: &ContentHash, out: &mut dyn Write, ) -> Result<u64, ArtifactError>

Stream the verified-then-decoded body of hash into out, returning the number of bytes written. This completes the streaming story Self::put already has on the write side: where Self::get returns an owned Vec<u8> (up to MAX_DECOMPRESSED_LEN resident), get_to lets a caller pipe a large artifact straight into a file, socket, or hashing sink without first materialising the whole decoded payload as a return value. Read more
Source§

fn list(&self) -> Result<Vec<ContentHash>, ArtifactError>

Enumerate the content hashes currently stored. Order is implementation-defined; callers that need a deterministic order must sort the result themselves. Read more
Source§

fn contains(&self, hash: &ContentHash) -> Result<bool, ArtifactError>

Cheap existence probe for hash: returns true if an entry is present, false otherwise. This is deliberately a stat-only check — it does NOT decode, decompress, or HMAC-verify the record, so it is dramatically cheaper than Self::get and suitable for the GC/audit roadmap’s “is this content already resident?” question. Read more
Source§

fn remove(&self, hash: &ContentHash) -> Result<bool, ArtifactError>

Remove the entry stored under hash. Returns true if a record was removed, false if nothing was stored under hash (a no-op delete is not an error — it mirrors HashMap::remove’s “was it there?” boolean and the POSIX unlink-of-missing convention GC callers expect). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more