Struct tough::RepositoryLoader

source ·
pub struct RepositoryLoader<'a> { /* private fields */ }
Expand description

A builder for settings with which to load a Repository. Required settings are provided in the RepositoryLoader::new function. Optional parameters can be added after calling new. Finally, call RepositoryLoader::load to load the Repository.

§Examples

§Basic usage:


let repository = RepositoryLoader::new(
    &tokio::fs::read(root).await.unwrap(),
    metadata_base_url,
    targets_base_url,
)
.load()
.await
.unwrap();

§With optional settings:


let repository = RepositoryLoader::new(
    &tokio::fs::read(root).await.unwrap(),
    metadata_base_url,
    targets_base_url,
)
.transport(FilesystemTransport)
.expiration_enforcement(ExpirationEnforcement::Unsafe)
.load()
.await
.unwrap();

Implementations§

source§

impl<'a> RepositoryLoader<'a>

source

pub fn new( root: &'a impl AsRef<[u8]>, metadata_base_url: Url, targets_base_url: Url ) -> Self

Create a new RepositoryLoader.

root is the content of a trusted root metadata file, which you must ship with your software using an out-of-band process. It should be a copy of the most recent root.json from your repository. (It’s okay if it becomes out of date later; the client establishes trust up to the most recent root.json file.)

metadata_base_url and targets_base_url are the base URLs where the client can find metadata (such as root.json) and targets (as listed in targets.json).

source

pub async fn load(self) -> Result<Repository>

Load and verify TUF repository metadata.

source

pub fn transport<T: Transport + Send + Sync + 'static>( self, transport: T ) -> Self

Set the transport. If no transport has been set, DefaultTransport will be used.

source

pub fn limits(self, limits: Limits) -> Self

Set a the repository Limits.

source

pub fn datastore<P: Into<PathBuf>>(self, datastore: P) -> Self

Set a datastore directory path. datastore is a directory on a persistent filesystem. This directory’s contents store the most recently fetched timestamp, snapshot, and targets metadata files to detect version rollback attacks.

You may chose to provide a PathBuf to a directory on a persistent filesystem, which must exist prior to calling RepositoryLoader::load. If no datastore is provided, a temporary directory will be created and cleaned up for for you.

source

pub fn expiration_enforcement(self, exp: ExpirationEnforcement) -> Self

Set the ExpirationEnforcement.

CAUTION: TUF metadata expiration dates, particularly timestamp.json, are designed to limit a replay attack window. By setting expiration_enforcement to Unsafe, you are disabling this feature of TUF. Use Safe unless you have a good reason to use Unsafe.

Trait Implementations§

source§

impl<'a> Clone for RepositoryLoader<'a>

source§

fn clone(&self) -> RepositoryLoader<'a>

Returns a copy 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<'a> Debug for RepositoryLoader<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RepositoryLoader<'a>

§

impl<'a> !RefUnwindSafe for RepositoryLoader<'a>

§

impl<'a> Send for RepositoryLoader<'a>

§

impl<'a> Sync for RepositoryLoader<'a>

§

impl<'a> Unpin for RepositoryLoader<'a>

§

impl<'a> !UnwindSafe for RepositoryLoader<'a>

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> 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,

§

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>,

§

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>,

§

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.