pub struct Repository { /* private fields */ }
Expand description
A TUF repository.
You can create a Repository
using a RepositoryLoader
.
Implementations§
Source§impl Repository
impl Repository
Sourcepub async fn cache<P1, P2, S>(
&self,
metadata_outdir: P1,
targets_outdir: P2,
targets_subset: Option<&[S]>,
cache_root_chain: bool,
) -> Result<()>
pub async fn cache<P1, P2, S>( &self, metadata_outdir: P1, targets_outdir: P2, targets_subset: Option<&[S]>, cache_root_chain: bool, ) -> Result<()>
Cache an entire or partial repository to disk, including all required metadata. The cached repo will be local, using filesystem paths.
metadata_outdir
is the directory where cached metadata files will be saved.targets_outdir
is the directory where cached targets files will be saved.targets_subset
is the list of targets to include in the cached repo. If no subset is specified (None
), then all targets are included in the cache.cache_root_chain
specifies whether or not we will cache all versions ofroot.json
.
Sourcepub async fn cache_metadata<P>(
&self,
metadata_outdir: P,
cache_root_chain: bool,
) -> Result<()>
pub async fn cache_metadata<P>( &self, metadata_outdir: P, cache_root_chain: bool, ) -> Result<()>
Cache only a repository’s metadata files (snapshot, targets, timestamp), including any delegated targets metadata. The cached files will be saved to the local filesystem.
metadata_outdir
is the directory where cached metadata files will be saved.cache_root_chain
specifies whether or not we will cache all versions ofroot.json
.
Source§impl Repository
impl Repository
Sourcepub fn targets(&self) -> &Signed<Targets>
pub fn targets(&self) -> &Signed<Targets>
Returns the list of targets present in the repository.
Sourcepub fn all_targets(&self) -> impl Iterator<Item = (&TargetName, &Target)> + '_
pub fn all_targets(&self) -> impl Iterator<Item = (&TargetName, &Target)> + '_
return a vec of all targets including all target files delegated by targets
Sourcepub async fn read_target(
&self,
name: &TargetName,
) -> Result<Option<impl Stream<Item = Result<Bytes>> + IntoVec<Error> + Send>>
pub async fn read_target( &self, name: &TargetName, ) -> Result<Option<impl Stream<Item = Result<Bytes>> + IntoVec<Error> + Send>>
Fetches a target from the repository.
If the repository metadata is expired or there is an issue making the request, Err
is
returned.
If the requested target is not listed in the repository metadata, Ok(None)
is returned.
Otherwise, a stream is returned, which provides access to the target contents before its
checksum is validated. If the maximum size is reached or there is a checksum mismatch, the
stream returns a error::Error
. Consumers of this library must not use data from the
stream if it returns an error.
Sourcepub async fn save_target<P>(
&self,
name: &TargetName,
outdir: P,
prepend: Prefix,
) -> Result<()>
pub async fn save_target<P>( &self, name: &TargetName, outdir: P, prepend: Prefix, ) -> Result<()>
Fetches a target from the repository and saves it to outdir
. Attempts to do this as safely
as possible by using path_clean
to eliminate ../
path traversals from the the target’s
name. Ensures that the resulting filepath is in outdir
or a child of outdir
.
§Parameters
name
: the target name.outdir
: the directory to save the target in.prepend
: Whether or not to prepend the sha digest when saving the target file.
§Preconditions and Behavior
outdir
must exist. For safety we want to canonicalize the path before we join to it.- intermediate directories will be created in
outdir
withcreate_dir_all
- Will error if the result of path resolution results in a filepath outside of
outdir
or outside of a delegated target’s correct path of delegation.
Sourcepub fn delegated_role(&self, name: &str) -> Option<&DelegatedRole>
pub fn delegated_role(&self, name: &str) -> Option<&DelegatedRole>
Return the named DelegatedRole
if found.
Trait Implementations§
Source§impl Clone for Repository
impl Clone for Repository
Source§fn clone(&self) -> Repository
fn clone(&self) -> Repository
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more