pub fn traverse_json(_attr: &Vec<String>, _json: &serde_json::Value) -> bool {
    if *_json == serde_json::Value::Null {
        println!("Error: passed null as json!");
        return false;
    }
    if _attr.len() == 0 {
        println!("Error: No attributes in List!");
        return false;
    }
    // inner node or
    if _json["OR"].is_array() {
        let _num_terms = _json["OR"].as_array().unwrap().len();
        if _num_terms >= 2 {
            let mut ret = false;
            for _i in 0usize.._num_terms {
                ret = ret || traverse_json(_attr, &_json["OR"][_i]);
            }
            return ret;
        } else {
            println!("Error: Invalid policy (OR with just a single child).");
            return false;
        }
    }
    // inner node and
    else if _json["AND"].is_array() {
        let _num_terms = _json["AND"].as_array().unwrap().len();
        if _num_terms >= 2 {
            let mut ret = true;
            for _i in 0usize.._num_terms {
                ret = ret && traverse_json(_attr, &_json["AND"][_i]);
            }
            return ret;
        } else {
            println!("Error: Invalid policy (AND with just a single child).");
            return false;
        }
    }
    // leaf node
    else if _json["ATT"] != serde_json::Value::Null {
        match _json["ATT"].as_str() {
            Some(s) => {
                // check if ATT in _attr list
                return (&_attr).into_iter().any(|x| x == s);
            }
            None => {
                println!("Error: in attribute String");
                return false;
            }
        }
    }
    // error
    else {
        println!("Error: Policy invalid. No AND or OR found");
        return false;
    }
}
// used to traverse / check policy tree
used to traverse / check policy tree
used to traverse / check policy tree
pub fn traverse_json(_attr: &Vec<String>, _json: &serde_json::Value) -> bool {
    if *_json == serde_json::Value::Null {
        println!("Error: passed null as json!");
        return false;
    }
    if _attr.len() == 0 {
        println!("Error: No attributes in List!");
        return false;
    }
    // inner node or
    if _json["OR"].is_array() {
        let _num_terms = _json["OR"].as_array().unwrap().len();
        if _num_terms >= 2 {
            let mut ret = false;
            for _i in 0usize.._num_terms {
                ret = ret || traverse_json(_attr, &_json["OR"][_i]);
            }
            return ret;
        } else {
            println!("Error: Invalid policy (OR with just a single child).");
            return false;
        }
    }
    // inner node and
    else if _json["AND"].is_array() {
        let _num_terms = _json["AND"].as_array().unwrap().len();
        if _num_terms >= 2 {
            let mut ret = true;
            for _i in 0usize.._num_terms {
                ret = ret && traverse_json(_attr, &_json["AND"][_i]);
            }
            return ret;
        } else {
            println!("Error: Invalid policy (AND with just a single child).");
            return false;
        }
    }
    // leaf node
    else if _json["ATT"] != serde_json::Value::Null {
        match _json["ATT"].as_str() {
            Some(s) => {
                // check if ATT in _attr list
                return (&_attr).into_iter().any(|x| x == s);
            }
            None => {
                println!("Error: in attribute String");
                return false;
            }
        }
    }
    // error
    else {
        println!("Error: Policy invalid. No AND or OR found");
        return false;
    }
}
pub fn traverse_json ( _attr : & Vec < String > , _json : & serde_json :: Value ) -> bool { if * _json == serde_json :: Value :: Null { println ! ( " " ) ; return false ; } if _attr . len ( ) == 0 { println ! ( " " ) ; return false ; } // inner node or if _json [ " " ] . is_array ( ) { let _num_terms = _json [ " " ] . as_array ( ) . unwrap ( ) . len ( ) ; if _num_terms >= 2 { let mut ret = false ; for _i in 0usize .. _num_terms { ret = ret || traverse_json ( _attr , & _json [ " " ] [ _i ] ) ; } return ret ; } else { println ! ( " " ) ; return false ; } } // inner node and else if _json [ " " ] . is_array ( ) { let _num_terms = _json [ " " ] . as_array ( ) . unwrap ( ) . len ( ) ; if _num_terms >= 2 { let mut ret = true ; for _i in 0usize .. _num_terms { ret = ret && traverse_json ( _attr , & _json [ " " ] [ _i ] ) ; } return ret ; } else { println ! ( " " ) ; return false ; } } // leaf node else if _json [ " " ] != serde_json :: Value :: Null { match _json [ " " ] . as_str ( ) { Some ( s ) => { // check if ATT in _attr list return ( & _attr ) . into_iter ( ) . any ( | x | x == s ) ; } None => { println ! ( " " ) ; return false ; } } } // error else { println ! ( " " ) ; return false ; } }
used to traverse / check policy tree
used to traverse / check policy tree
_attr
&Vec<String>
_json
&serde_json::Value
_attr
&Vec<String>
_json
&serde_json::Value