Skip to main content

InMemoryArtifactStore

Struct InMemoryArtifactStore 

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

In-memory artifact store. Intended for tests, fuzzers, and ephemeral caches.

§SECURITY WARNING: NO integrity or signature verification

Unlike DiskArtifactStore, this store performs NO HMAC signing and NO HMAC/content-hash verification on put / get. It stores the plaintext payload in a HashMap and hands it straight back. The hmac_key below is accepted only so the constructor signature matches the disk store’s; it is never used to sign or verify anything (hence #[allow(dead_code)]).

This is safe only because the in-memory map is the trust boundary: the bytes returned are exactly the bytes a (trusted) caller inserted in the same process, so there is no untrusted on-the-wire/on-disk envelope to authenticate. Do NOT use this type to back any data path that crosses a trust boundary (untrusted input, persistence, IPC, network). For anything that must detect tampering or forged blobs, use DiskArtifactStore, which signs and constant-time verifies every record. Treat this store as test/ephemeral-only.

Implementations§

Source§

impl InMemoryArtifactStore

Source

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

Construct an empty in-memory store under hmac_key.

Trait Implementations§

Source§

impl ArtifactStore for InMemoryArtifactStore

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