Struct tough::editor::RepositoryEditor[][src]

pub struct RepositoryEditor { /* fields omitted */ }

RepositoryEditor contains the various bits of data needed to construct or edit a TUF repository.

A new repository may be started using the new() method.

An existing tough::Repository may be loaded and edited using the from_repo() method. When a repo is loaded in this way, versions and expirations are discarded. It is good practice to update these whenever a repo is changed.

Targets, versions, and expirations may be added to their respective roles via the provided “setter” methods. The final step in the process is the sign() method, which takes a given set of signing keys, builds each of the roles using the data provided, and signs the roles. This results in a SignedRepository which can be used to write the repo to disk.

The following should only be used in a repository that utilizes delegated targets RepositoryEditor uses a modal design to edit Targets. TargetsEditor is used to perform all actions on a specified Targets. To change the Targets being used call change_delegated_targets() to create a new TargetsEditor for the specified role. To sign a Targets role from the TargetsEditor use sign_targets_editor(). This will clear out the targets editor and insert the newly signed targets in signed_targets.

To update an existing targets from a metadata file use update_delegated_targets().

To add a new role from metadata to the Targets in TargetsEditor use add_role().

Implementations

impl RepositoryEditor[src]

pub fn new<P>(root_path: P) -> Result<Self> where
    P: AsRef<Path>, 
[src]

Create a new, bare RepositoryEditor

pub fn from_repo<P>(root_path: P, repo: Repository) -> Result<RepositoryEditor> where
    P: AsRef<Path>, 
[src]

Given a tough::Repository and the path to a valid root.json, create a RepositoryEditor. This RepositoryEditor will include all of the targets and bits of _extra metadata from the roles included. It will not, however, include the versions or expirations and the user is expected to set them.

pub fn sign(self, keys: &[Box<dyn KeySource>]) -> Result<SignedRepository>[src]

Builds and signs each required role and returns a complete signed set of TUF repository metadata.

While RepositoryEditors fields are all Options, this step requires, at the very least, that the “version” and “expiration” field is set for each role; e.g. targets_version, targets_expires, etc.

pub fn targets(&mut self, targets: Signed<Targets>) -> Result<&mut Self>[src]

Add an existing Targets struct to the repository.

pub fn snapshot(&mut self, snapshot: Snapshot) -> Result<&mut Self>[src]

Add an existing Snapshot to the repository. Only the _extra data is preserved

pub fn timestamp(&mut self, timestamp: Timestamp) -> Result<&mut Self>[src]

Add an existing Timestamp to the repository. Only the _extra data is preserved

pub fn add_target(&mut self, name: &str, target: Target) -> Result<&mut Self>[src]

Add a Target to the repository

pub fn remove_target(&mut self, name: &str) -> Result<&mut Self>[src]

Remove a Target from the repository

pub fn add_target_path<P>(&mut self, target_path: P) -> Result<&mut Self> where
    P: AsRef<Path>, 
[src]

Add a target to the repository using its path

Note: This function builds a Target synchronously; no multithreading or parallelism is used. If you have a large number of targets to add, and require advanced performance, you may want to construct Targets directly in parallel and use add_target().

pub fn add_target_paths<P>(&mut self, targets: Vec<P>) -> Result<&mut Self> where
    P: AsRef<Path>, 
[src]

Add a list of target paths to the repository

See the note on add_target_path() regarding performance.

pub fn build_target<P>(target_path: P) -> Result<(String, Target)> where
    P: AsRef<Path>, 
[src]

Builds a target struct for the given path

pub fn clear_targets(&mut self) -> Result<&mut Self>[src]

Remove all targets from this repo

pub fn delegate_role(
    &mut self,
    name: &str,
    key_source: &[Box<dyn KeySource>],
    paths: PathSet,
    threshold: NonZeroU64,
    expiration: DateTime<Utc>,
    version: NonZeroU64
) -> Result<&mut Self>
[src]

Delegate target with name as a DelegatedRole of the Targets in targets_editor This should be used if a role needs to be created by a user with snapshot.json, timestamp.json, and the new role’s keys.

pub fn snapshot_version(&mut self, snapshot_version: NonZeroU64) -> &mut Self[src]

Set the Snapshot version

pub fn snapshot_expires(&mut self, snapshot_expires: DateTime<Utc>) -> &mut Self[src]

Set the Snapshot expiration

pub fn targets_version(
    &mut self,
    targets_version: NonZeroU64
) -> Result<&mut Self>
[src]

Set the Targets version

pub fn targets_expires(
    &mut self,
    targets_expires: DateTime<Utc>
) -> Result<&mut Self>
[src]

Set the Targets expiration

pub fn timestamp_version(&mut self, timestamp_version: NonZeroU64) -> &mut Self[src]

Set the Timestamp version

pub fn timestamp_expires(
    &mut self,
    timestamp_expires: DateTime<Utc>
) -> &mut Self
[src]

Set the Timestamp expiration

pub fn sign_targets_editor(
    &mut self,
    keys: &[Box<dyn KeySource>]
) -> Result<&mut Self>
[src]

Takes the current Targets from targets_editor and inserts the role to its proper place in signed_targets Sets targets_editor to None Must be called before change_delegated_targets()

pub fn change_delegated_targets(&mut self, role: &str) -> Result<&mut Self>[src]

Changes the targets refered to in targets_editor to role All Targets related calls will now be called on the Targets role named role Throws error if the targets_editor was not cleared using sign_targets_editor() Clones the desired targets from signed_targets and creates a TargetsEditor for it

pub fn update_delegated_targets(
    &mut self,
    name: &str,
    metadata_url: &str
) -> Result<&mut Self>
[src]

Updates the metadata for the Targets role named name This method is used to load in a Targets metadata file located at metadata_url and update the repository’s metadata for the role This method uses the result of SignedDelegatedTargets::write() Clears the current targets_editor

pub fn add_role(
    &mut self,
    name: &str,
    metadata_url: &str,
    paths: PathSet,
    threshold: NonZeroU64,
    keys: Option<HashMap<Decoded<Hex>, Key>>
) -> Result<&mut Self>
[src]

Adds a role to the targets currently in targets_editor using a metadata file located at metadata_url/name.json add_role() uses TargetsEditor::add_role() to add a role from an existing metadata file.

Trait Implementations

impl Debug for RepositoryEditor[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,