A requested capability list as a grant's set: nonempty, and every entry delegable.
(requested: &[String])
| 237 | /// A requested capability list as a grant's set: nonempty, and every entry |
| 238 | /// delegable. |
| 239 | pub fn grant_capabilities(requested: &[String]) -> Result<BTreeSet<String>, GrantError> { |
| 240 | if requested.is_empty() { |
| 241 | return Err(GrantError::InvalidCapabilities( |
| 242 | "name the capabilities the sandbox needs".to_string(), |
| 243 | )); |
| 244 | } |
| 245 | let mut out = BTreeSet::new(); |
| 246 | for capability in requested { |
| 247 | if !DELEGABLE_CAPABILITIES.contains(&capability.as_str()) { |
| 248 | return Err(GrantError::InvalidCapabilities(format!( |
| 249 | "'{capability}' cannot be delegated to a sandbox" |
| 250 | ))); |
| 251 | } |
| 252 | out.insert(capability.clone()); |
| 253 | } |
| 254 | Ok(out) |
| 255 | } |
| 256 | |
| 257 | /// Where sandbox grants live. The handlers only ever reach grants through |
| 258 | /// this trait; a host that persists grants (its own database) implements it |