/// Checks the dependencies of the given crate from the given cargo metadata to see if they are on
/// the whitelist. Returns a list of illegal dependencies.
Checks the dependencies of the given crate from the given cargo metadata to see if they are on
the whitelist. Returns a list of illegal dependencies.
Checks the dependencies of the given crate from the given cargo metadata to see if they are on the whitelist . Returns a list of illegal dependencies .
fn check_crate_whitelist<'a, 'b>(
    whitelist: &'a HashSet<Crate>,
    resolve: &'a Resolve,
    visited: &'b mut BTreeSet<CrateVersion<'a>>,
    krate: CrateVersion<'a>,
    must_be_on_whitelist: bool,
) -> BTreeSet<Crate<'a>> {
    // Will contain bad deps
    let mut unapproved = BTreeSet::new();
    // Check if we have already visited this crate
    if visited.contains(&krate) {
        return unapproved;
    }
    visited.insert(krate);
    // If this path is in-tree, we don't require it to be on the whitelist
    if must_be_on_whitelist {
        // If this dependency is not on the WHITELIST, add to bad set
        if !whitelist.contains(&krate.into()) {
            unapproved.insert(krate.into());
        }
    }
    // Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!)
    let to_check = resolve
        .nodes
        .iter()
        .find(|n| n.id.starts_with(&krate.id_str()))
        .expect("crate does not exist");
    for dep in to_check.dependencies.iter() {
        let (krate, is_path_dep) = CrateVersion::from_str(dep);
        let mut bad = check_crate_whitelist(whitelist, resolve, visited, krate, !is_path_dep);
        unapproved.append(&mut bad);
    }
    unapproved
}
fn check_crate_whitelist < ' a , ' b > ( whitelist : & ' a HashSet < Crate > , resolve : & ' a Resolve , visited : & ' b mut BTreeSet < CrateVersion < ' a > > , krate : CrateVersion < ' a > , must_be_on_whitelist : bool , ) -> BTreeSet < Crate < ' a > > { // Will contain bad deps let mut unapproved = BTreeSet :: new ( ) ; // Check if we have already visited this crate if visited . contains ( & krate ) { return unapproved ; } visited . insert ( krate ) ; // If this path is in-tree, we don't require it to be on the whitelist if must_be_on_whitelist { // If this dependency is not on the WHITELIST, add to bad set if ! whitelist . contains ( & krate . into ( ) ) { unapproved . insert ( krate . into ( ) ) ; } } // Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!) let to_check = resolve . nodes . iter ( ) . find ( | n | n . id . starts_with ( & krate . id_str ( ) ) ) . expect ( " " ) ; for dep in to_check . dependencies . iter ( ) { let ( krate , is_path_dep ) = CrateVersion :: from_str ( dep ) ; let mut bad = check_crate_whitelist ( whitelist , resolve , visited , krate , ! is_path_dep ) ; unapproved . append ( & mut bad ) ; } unapproved }
Checks the dependencies of the given crate from the given cargo metadata to see if they are on
the whitelist.
Checks the dependencies of the given crate from the given cargo metadata to see if they are on the whitelist .
whitelist
&'a HashSet<Crate>
resolve
&'a Resolve
visited
&'b mut BTreeSet<CrateVersion<'a>>
krate
CrateVersion<'a>
must_be_on_whitelist
bool