Skip to main content

parse_file

Function parse_file 

Source
pub fn parse_file(
    path: &Path,
    cap: &impl Has<FsRead>,
) -> Result<ParsedFile, String>
Expand description

Parses a .rs file from disk into a ParsedFile.

Requires an FsRead capability token, proving the caller has permission to read files. This is the dogfood example — cargo capsec audit flagged this function’s std::fs::read_to_string call, and now it’s gated by the capsec type system.

§Example

use capsec_core::root::test_root;
use capsec_core::permission::FsRead;

let root = test_root();
let cap = root.grant::<FsRead>();
let parsed = parse_file(Path::new("src/main.rs"), &cap).unwrap();