/// Get a reference to the description needed to verify the target defined by the given
/// `TargetPath`. Returns an `Error` if the target is not defined in the trusted
/// metadata. This may mean the target exists somewhere in the metadata, but the chain of trust
/// to that target may be invalid or incomplete.
Get a reference to the description needed to verify the target defined by the given
`TargetPath`. Returns an `Error` if the target is not defined in the trusted
metadata. This may mean the target exists somewhere in the metadata, but the chain of trust
to that target may be invalid or incomplete.
Get a reference to the description needed to verify the target defined by the given ` TargetPath ` . Returns an ` Error ` if the target is not defined in the trusted metadata . This may mean the target exists somewhere in the metadata but the chain of trust to that target may be invalid or incomplete .
pub fn target_description(&self, target_path: &TargetPath) -> Result<TargetDescription> {
        let _ = self.trusted_root_unexpired()?;
        let _ = self.trusted_snapshot_unexpired()?;
        let targets = self.trusted_targets_unexpired()?;
        if let Some(d) = targets.targets().get(target_path) {
            return Ok(d.clone());
        }
        fn lookup<D: DataInterchange>(
            tuf: &Database<D>,
            default_terminate: bool,
            current_depth: u32,
            target_path: &TargetPath,
            delegations: &Delegations,
            parents: &[HashSet<TargetPath>],
            visited: &mut HashSet<MetadataPath>,
        ) -> (bool, Option<TargetDescription>) {
            for delegation in delegations.roles() {
                if visited.contains(delegation.role()) {
                    return (delegation.terminating(), None);
                }
                let _ = visited.insert(delegation.role().clone());
                let mut new_parents = parents.to_owned();
                new_parents.push(delegation.paths().clone());
                if current_depth > 0 && !target_path.matches_chain(parents) {
                    return (delegation.terminating(), None);
                }
                let trusted_delegation = match tuf.trusted_delegations.get(delegation.role()) {
                    Some(trusted_delegation) => trusted_delegation,
                    None => return (delegation.terminating(), None),
                };
                if trusted_delegation.expires() <= &Utc::now() {
                    return (delegation.terminating(), None);
                }
                if let Some(target) = trusted_delegation.targets().get(target_path) {
                    return (delegation.terminating(), Some(target.clone()));
                }
                if let Some(trusted_child_delegation) = trusted_delegation.delegations() {
                    let mut new_parents = parents.to_vec();
                    new_parents.push(delegation.paths().clone());
                    let (term, res) = lookup(
                        tuf,
                        delegation.terminating(),
                        current_depth + 1,
                        target_path,
                        trusted_child_delegation,
                        &new_parents,
                        visited,
                    );
                    if term {
                        return (true, res);
                    } else if res.is_some() {
                        return (term, res);
                    }
                }
            }
            (default_terminate, None)
        }
        match targets.delegations() {
            Some(d) => {
                let mut visited = HashSet::new();
                lookup(self, false, 0, target_path, d, &[], &mut visited)
                    .1
                    .ok_or(Error::TargetUnavailable)
            }
            None => Err(Error::TargetUnavailable),
        }
    }
pub fn target_description ( & self , target_path : & TargetPath ) -> Result < TargetDescription > { let _ = self . trusted_root_unexpired ( ) ? ; let _ = self . trusted_snapshot_unexpired ( ) ? ; let targets = self . trusted_targets_unexpired ( ) ? ; if let Some ( d ) = targets . targets ( ) . get ( target_path ) { return Ok ( d . clone ( ) ) ; } fn lookup < D : DataInterchange > ( tuf : & Database < D > , default_terminate : bool , current_depth : u32 , target_path : & TargetPath , delegations : & Delegations , parents : & [ HashSet < TargetPath > ] , visited : & mut HashSet < MetadataPath > , ) -> ( bool , Option < TargetDescription > ) { for delegation in delegations . roles ( ) { if visited . contains ( delegation . role ( ) ) { return ( delegation . terminating ( ) , None ) ; } let _ = visited . insert ( delegation . role ( ) . clone ( ) ) ; let mut new_parents = parents . to_owned ( ) ; new_parents . push ( delegation . paths ( ) . clone ( ) ) ; if current_depth > 0 && ! target_path . matches_chain ( parents ) { return ( delegation . terminating ( ) , None ) ; } let trusted_delegation = match tuf . trusted_delegations . get ( delegation . role ( ) ) { Some ( trusted_delegation ) => trusted_delegation , None => return ( delegation . terminating ( ) , None ) , } ; if trusted_delegation . expires ( ) <= & Utc :: now ( ) { return ( delegation . terminating ( ) , None ) ; } if let Some ( target ) = trusted_delegation . targets ( ) . get ( target_path ) { return ( delegation . terminating ( ) , Some ( target . clone ( ) ) ) ; } if let Some ( trusted_child_delegation ) = trusted_delegation . delegations ( ) { let mut new_parents = parents . to_vec ( ) ; new_parents . push ( delegation . paths ( ) . clone ( ) ) ; let ( term , res ) = lookup ( tuf , delegation . terminating ( ) , current_depth + 1 , target_path , trusted_child_delegation , & new_parents , visited , ) ; if term { return ( true , res ) ; } else if res . is_some ( ) { return ( term , res ) ; } } } ( default_terminate , None ) } match targets . delegations ( ) { Some ( d ) => { let mut visited = HashSet :: new ( ) ; lookup ( self , false , 0 , target_path , d , & [ ] , & mut visited ) . 1 . ok_or ( Error :: TargetUnavailable ) } None => Err ( Error :: TargetUnavailable ) , } }
Get a reference to the description needed to verify the target defined by the given
`TargetPath`.
Get a reference to the description needed to verify the target defined by the given ` TargetPath ` .
&self
target_path
&TargetPath