capsec-macro
Procedural macros for the capsec capability-based security system.
You probably want to depend on the capsec facade crate instead of using this directly — it re-exports these macros.
Macros
#[capsec::main]
Injects CapRoot creation into a function entry point. Removes the first CapRoot parameter and prepends let root = capsec::root(); to the body.
When combining with #[tokio::main], place #[capsec::main] above:
async
#[capsec::context]
Transforms a struct with permission-type fields into a capability context. Generates Cap<P> fields, a new(root) constructor, and Has<P> impls for each field.
// Generated: AppCtx::new(&root), impl Has<FsRead> for AppCtx, impl Has<NetConnect> for AppCtx
For async/threaded code, use the send variant to generate SendCap<P> fields:
// AsyncCtx is Send + Sync, can be wrapped in Arc
#[capsec::requires(...)]
Declares and validates a function's capability requirements.
With impl Has<P> bounds, the compiler already enforces the trait bounds — the macro emits only a #[doc] attribute:
With concrete context types, use on = param to emit a compile-time assertion that the parameter type implements Has<P>:
#[capsec::deny(...)]
Marks a function as capability-free. cargo capsec audit will promote any ambient authority call inside a #[deny] function to critical risk.
Supported permissions
fs::read, fs::write, fs::all, net::connect, net::bind, net::all, env::read, env::write, spawn, all
License
Apache-2.0