Struct Repository

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

A TUF repository.

You can create a Repository using a RepositoryLoader.

Implementations§

Source§

impl Repository

Source

pub async fn cache<P1, P2, S>( &self, metadata_outdir: P1, targets_outdir: P2, targets_subset: Option<&[S]>, cache_root_chain: bool, ) -> Result<()>
where P1: AsRef<Path>, P2: AsRef<Path>, S: AsRef<str>,

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 of root.json.
Source

pub async fn cache_metadata<P>( &self, metadata_outdir: P, cache_root_chain: bool, ) -> Result<()>
where P: AsRef<Path>,

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 of root.json.
Source§

impl Repository

Source

pub fn targets(&self) -> &Signed<Targets>

Returns the list of targets present in the repository.

Source

pub fn root(&self) -> &Signed<Root>

Returns a reference to the signed root

Source

pub fn snapshot(&self) -> &Signed<Snapshot>

Returns a reference to the signed snapshot

Source

pub fn timestamp(&self) -> &Signed<Timestamp>

Returns a reference to the signed timestamp

Source

pub fn all_targets(&self) -> impl Iterator<Item = (&TargetName, &Target)> + '_

return a vec of all targets including all target files delegated by targets

Source

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.

Source

pub async fn save_target<P>( &self, name: &TargetName, outdir: P, prepend: Prefix, ) -> Result<()>
where P: AsRef<Path>,

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 with create_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.
Source

pub fn delegated_role(&self, name: &str) -> Option<&DelegatedRole>

Return the named DelegatedRole if found.

Trait Implementations§

Source§

impl Clone for Repository

Source§

fn clone(&self) -> Repository

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Repository

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> ErasedDestructor for T
where T: 'static,