1use crate::handle::Handle;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[repr(transparent)]
11pub struct RvfMountHandle(pub Handle);
12
13impl RvfMountHandle {
14 #[inline]
16 #[must_use]
17 pub const fn new(id: u32, generation: u32) -> Self {
18 Self(Handle::new(id, generation))
19 }
20
21 #[inline]
23 #[must_use]
24 pub const fn null() -> Self {
25 Self(Handle::null())
26 }
27
28 #[inline]
30 #[must_use]
31 pub const fn is_null(&self) -> bool {
32 self.0.is_null()
33 }
34
35 #[inline]
37 #[must_use]
38 pub const fn raw(&self) -> Handle {
39 self.0
40 }
41}
42
43impl Default for RvfMountHandle {
44 fn default() -> Self {
45 Self::null()
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
55#[repr(C)]
56pub struct RvfComponentId {
57 pub mount: RvfMountHandle,
59
60 pub component_index: u32,
62}
63
64impl RvfComponentId {
65 #[inline]
67 #[must_use]
68 pub const fn new(mount: RvfMountHandle, component_index: u32) -> Self {
69 Self {
70 mount,
71 component_index,
72 }
73 }
74
75 #[inline]
77 #[must_use]
78 pub const fn root(mount: RvfMountHandle) -> Self {
79 Self {
80 mount,
81 component_index: 0,
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
88#[repr(u8)]
89pub enum RvfVerifyStatus {
90 SignatureValid = 0,
92
93 SignatureInvalid = 1,
95
96 ManifestInvalid = 2,
98
99 ComponentMissing = 3,
101
102 ProofPolicyInvalid = 4,
104
105 CapabilitiesInsufficient = 5,
107}
108
109impl RvfVerifyStatus {
110 #[inline]
112 #[must_use]
113 pub const fn is_valid(&self) -> bool {
114 matches!(self, Self::SignatureValid)
115 }
116
117 #[inline]
119 #[must_use]
120 pub const fn as_str(&self) -> &'static str {
121 match self {
122 Self::SignatureValid => "Signature valid",
123 Self::SignatureInvalid => "Signature invalid",
124 Self::ManifestInvalid => "Manifest invalid",
125 Self::ComponentMissing => "Component missing",
126 Self::ProofPolicyInvalid => "Proof policy invalid",
127 Self::CapabilitiesInsufficient => "Capabilities insufficient",
128 }
129 }
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
136#[repr(transparent)]
137pub struct WitTypeId(pub u32);
138
139impl WitTypeId {
140 pub const NONE: Self = Self(0);
142
143 #[inline]
145 #[must_use]
146 pub const fn new(id: u32) -> Self {
147 Self(id)
148 }
149
150 #[inline]
152 #[must_use]
153 pub const fn is_none(&self) -> bool {
154 self.0 == 0
155 }
156}
157
158impl Default for WitTypeId {
159 fn default() -> Self {
160 Self::NONE
161 }
162}
163
164#[cfg(test)]
165mod tests {
166 use super::*;
167
168 #[test]
169 fn test_rvf_mount_handle() {
170 let h = RvfMountHandle::new(1, 2);
171 assert!(!h.is_null());
172 }
173
174 #[test]
175 fn test_rvf_component_id() {
176 let mount = RvfMountHandle::new(1, 0);
177 let component = RvfComponentId::new(mount, 3);
178 assert_eq!(component.component_index, 3);
179 }
180
181 #[test]
182 fn test_rvf_verify_status() {
183 assert!(RvfVerifyStatus::SignatureValid.is_valid());
184 assert!(!RvfVerifyStatus::SignatureInvalid.is_valid());
185 }
186}