#io

open-ambient

Open files and directories with constant paths

4 releases (2 breaking)

0.2.0 Jun 23, 2022
0.1.0 Dec 24, 2021
0.0.1 Jul 14, 2021
0.0.0 Jul 14, 2021

#96 in #io

Download history 1/week @ 2022-03-09 17/week @ 2022-03-16 7/week @ 2022-03-23 2/week @ 2022-03-30 4/week @ 2022-04-06 3/week @ 2022-04-13 2/week @ 2022-04-20 23/week @ 2022-04-27 21/week @ 2022-05-04 47/week @ 2022-05-11 16/week @ 2022-05-18 14/week @ 2022-05-25 30/week @ 2022-06-01 7/week @ 2022-06-08 4/week @ 2022-06-15 26/week @ 2022-06-22

68 downloads per month

Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT

13KB

open-ambient

Open files and directories with constant paths

Github Actions CI Status crates.io page docs.rs docs

One of the uses for ambient-authority is to mark places in the code which may be opening files or other resources in ways that may be influenced by untrusted inputs. Paths or other identifiers which are constant and known at compile time are safe. This crate provides macros for use with cap-std which open files and directories in a way that requires the paths to be constant and in a way that allows them to be ignored in a clippy scan for use of dynamic ambient authority.

To use, it add #![deny(clippy::disallowed_method)] to your code and copy the clippy.toml file, as described here, for example:

#![deny(clippy::disallowed_method)]

use open_ambient::open_ambient_file;

fn main() {
    let fine = open_ambient_file!("Cargo.toml").unwrap();
    // ... do stuff with `fine`
    drop(fine);

    let risky = std::fs::File::open("Cargo.toml").unwrap();
    // ... do stuff with `risky`
    drop(risky);
}

And run clippy configured with these instructions. The above code gets just one error:

error: use of a disallowed method `std::fs::File::open`
  --> test.rs:10:19
   |
10 |     let risky = std::fs::File::open("Cargo.toml").unwrap();
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

The open_ambient_file! line does not get an error, while the std::fs::File::open line does.

Dependencies

~1–6.5MB
~120K SLoC