Skip to main content

astrid_capabilities/
handle.rs

1use serde::{Deserialize, Serialize};
2
3/// A cryptographic handle representing an open directory within the VFS.
4/// This acts as a capability token preventing the guest from forging arbitrary paths.
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub struct DirHandle(pub String);
7
8#[expect(clippy::new_without_default)]
9impl DirHandle {
10    /// Create a new directory handle.
11    #[must_use]
12    pub fn new() -> Self {
13        Self(uuid::Uuid::new_v4().to_string())
14    }
15}
16
17impl std::fmt::Display for DirHandle {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        write!(f, "{}", self.0)
20    }
21}
22
23/// A cryptographic handle representing an open file within the VFS.
24#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
25pub struct FileHandle(pub String);
26
27#[expect(clippy::new_without_default)]
28impl FileHandle {
29    /// Create a new file handle.
30    #[must_use]
31    pub fn new() -> Self {
32        Self(uuid::Uuid::new_v4().to_string())
33    }
34}
35
36impl std::fmt::Display for FileHandle {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        write!(f, "{}", self.0)
39    }
40}