pub struct ArtifactCache { /* private fields */ }Implementations§
Source§impl ArtifactCache
impl ArtifactCache
pub fn new(root: impl Into<PathBuf>, trust: TrustPolicy) -> Self
Sourcepub fn with_signature_policy(self, policy: SignaturePolicy) -> Self
pub fn with_signature_policy(self, policy: SignaturePolicy) -> Self
With SignaturePolicy::Require, refuse every artifact whose manifest signature was not
verified against a key in this cache’s TrustPolicy::EmbeddedKeys, instead of accepting
a digest-only lock entry.
Sourcepub fn with_download_options(self, options: DownloadOptions) -> Self
pub fn with_download_options(self, options: DownloadOptions) -> Self
Replace the download tuning (timeouts, retries, progress, cancellation).
pub fn download_options(&self) -> &DownloadOptions
Sourcepub fn with_url_override(
self,
resolve: impl Fn(&ComponentLockEntry) -> String + Send + Sync + 'static,
) -> Self
pub fn with_url_override( self, resolve: impl Fn(&ComponentLockEntry) -> String + Send + Sync + 'static, ) -> Self
Fetch artifacts from resolve(entry) instead of the lock entry’s own url.
Intended for air-gapped or corporate mirrors. Integrity never depends on the URL: the
archive size, SHA-256 and the manifest signature are still checked against the lock.
A returned file:// URL is read from disk.
Sourcepub fn with_verified_stamp(self, enabled: bool) -> Self
pub fn with_verified_stamp(self, enabled: bool) -> Self
Trust a verified stamp instead of re-hashing an installed library on every process start. Off by default.
After the first full check a stamp (archive sha, size, mtime in nanoseconds, and on Unix device, inode and ctime) is written next to the object. A later process that finds the library still matching the stamp skips reading and hashing it; the manifest digest, identity and signature are still verified every time.
Still caught: replacing the file (new inode), size changes, and edits that change the
mtime or, on Unix, the ctime. Not caught: a same-size in-place edit that restores the
mtime on Windows, or by an attacker who can forge Unix ctime. Anyone able to do that can
already rewrite the cache (including the stamp), so the stamp is honoured only while the
cache root and its object directory are owned by the current user and not writable by
group or others (Unix); otherwise every verification hashes the library. The cache creates
its directories 0700.
Sourcepub fn offline(self, offline: bool) -> Self
pub fn offline(self, offline: bool) -> Self
Disable network downloads: Self::install fails a missing artifact with
ComponentError::Offline instead of attempting a request, and a damaged installed
artifact with ComponentError::CachedObjectInvalid. An artifact already verified on
disk (or served via a file:// URL) is unaffected.
pub fn root(&self) -> &Path
pub fn object_path( &self, entry: &ComponentLockEntry, ) -> Result<PathBuf, ComponentError>
Sourcepub fn verify_cached(
&self,
entry: &ComponentLockEntry,
) -> Result<CachedArtifact, ComponentError>
pub fn verify_cached( &self, entry: &ComponentLockEntry, ) -> Result<CachedArtifact, ComponentError>
Verify an installed object in place: checks it against the lock entry (skipping the
library hash when a current verified stamp says it is unchanged) but never downloads or
removes anything, and writes nothing but the verified stamp when the cache was built with
[Self::with_verified_stamp(true)].
Unlike Self::install, a failing check is reported instead of repaired, and the error
says which check failed (digest, size, manifest, signature) – so a caller can tell
“installed and damaged” apart from “never installed” and log or report a repair.
pub fn install( &self, entry: &ComponentLockEntry, ) -> Result<CachedArtifact, ComponentError>
Sourcepub fn install_from_reader(
&self,
entry: &ComponentLockEntry,
reader: impl Read,
) -> Result<CachedArtifact, ComponentError>
pub fn install_from_reader( &self, entry: &ComponentLockEntry, reader: impl Read, ) -> Result<CachedArtifact, ComponentError>
Install an archive from reader, honouring this cache’s progress and cancellation
settings (see DownloadOptions). Never retries: the reader cannot be rewound.
Source§impl ArtifactCache
impl ArtifactCache
Sourcepub fn list_objects(&self) -> Result<Vec<CachedObject>, ComponentError>
pub fn list_objects(&self) -> Result<Vec<CachedObject>, ComponentError>
Every installed object, sorted by digest. A missing cache directory lists as empty.
Sourcepub fn remove_object(
&self,
sha256: &str,
) -> Result<RemovalReport, ComponentError>
pub fn remove_object( &self, sha256: &str, ) -> Result<RemovalReport, ComponentError>
Remove one object and its sidecar files. Ok with an empty report when absent. Waits for
an install of the same object in another thread or process to finish first.