ps_uuid/constants.rs
1//! Well-known UUID constants.
2
3use crate::{uuid, UUID};
4
5impl UUID {
6 // =========================================================================
7 // Fundamental
8 // =========================================================================
9
10 /// The nil UUID, where all bits are set to zero.
11 ///
12 /// ```text
13 /// 00000000-0000-0000-0000-000000000000
14 /// ```
15 pub const NIL: Self = Self { bytes: [0; 16] };
16
17 /// The max UUID, where all bits are set to one.
18 ///
19 /// ```text
20 /// ffffffff-ffff-ffff-ffff-ffffffffffff
21 /// ```
22 pub const MAX: Self = Self { bytes: [0xFF; 16] };
23
24 // =========================================================================
25 // RFC 4122 Namespaces
26 // =========================================================================
27
28 /// The DNS namespace UUID, for generating v3/v5 UUIDs from domain names.
29 ///
30 /// Defined in RFC 4122 Appendix C.
31 ///
32 /// ```text
33 /// 6ba7b810-9dad-11d1-80b4-00c04fd430c8
34 /// ```
35 pub const NS_DNS: Self = uuid!("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
36
37 /// The URL namespace UUID, for generating v3/v5 UUIDs from URLs.
38 ///
39 /// Defined in RFC 4122 Appendix C.
40 ///
41 /// ```text
42 /// 6ba7b811-9dad-11d1-80b4-00c04fd430c8
43 /// ```
44 pub const NS_URL: Self = uuid!("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
45
46 /// The OID namespace UUID, for generating v3/v5 UUIDs from ISO OIDs.
47 ///
48 /// Defined in RFC 4122 Appendix C.
49 ///
50 /// ```text
51 /// 6ba7b812-9dad-11d1-80b4-00c04fd430c8
52 /// ```
53 pub const NS_OID: Self = uuid!("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
54
55 /// The X.500 namespace UUID, for generating v3/v5 UUIDs from X.500 DNs.
56 ///
57 /// Defined in RFC 4122 Appendix C.
58 ///
59 /// ```text
60 /// 6ba7b814-9dad-11d1-80b4-00c04fd430c8
61 /// ```
62 pub const NS_X500: Self = uuid!("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
63
64 // =========================================================================
65 // Bluetooth
66 // =========================================================================
67
68 /// The Bluetooth Base UUID.
69 ///
70 /// Used to construct full 128-bit UUIDs from 16-bit and 32-bit Bluetooth
71 /// identifiers. To convert a 16-bit UUID `xxxx`: `0000xxxx-0000-1000-8000-00805f9b34fb`.
72 ///
73 /// Defined in the Bluetooth Core Specification.
74 ///
75 /// ```text
76 /// 00000000-0000-1000-8000-00805f9b34fb
77 /// ```
78 pub const BLUETOOTH_BASE: Self = uuid!("00000000-0000-1000-8000-00805f9b34fb");
79
80 // =========================================================================
81 // GPT Partition Types
82 // =========================================================================
83
84 /// EFI System Partition type GUID.
85 ///
86 /// The FAT-formatted partition containing UEFI bootloaders and drivers.
87 ///
88 /// ```text
89 /// c12a7328-f81f-11d2-ba4b-00a0c93ec93b
90 /// ```
91 pub const GPT_EFI_SYSTEM: Self = uuid!("c12a7328-f81f-11d2-ba4b-00a0c93ec93b");
92
93 /// Linux filesystem data partition type GUID.
94 ///
95 /// The generic type for Linux filesystem partitions (ext4, xfs, btrfs, etc.).
96 ///
97 /// ```text
98 /// 0fc63daf-8483-4772-8e79-3d69d8477de4
99 /// ```
100 pub const GPT_LINUX_FS: Self = uuid!("0fc63daf-8483-4772-8e79-3d69d8477de4");
101
102 /// Linux swap partition type GUID.
103 ///
104 /// ```text
105 /// 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
106 /// ```
107 pub const GPT_LINUX_SWAP: Self = uuid!("0657fd6d-a4ab-43c4-84e5-0933c84b4f4f");
108
109 /// Linux root partition (x86-64) type GUID.
110 ///
111 /// Used by systemd-gpt-auto-generator for automatic root discovery.
112 ///
113 /// ```text
114 /// 4f68bce3-e8cd-4db1-96e7-fbcaf984b709
115 /// ```
116 pub const GPT_LINUX_ROOT_X86_64: Self = uuid!("4f68bce3-e8cd-4db1-96e7-fbcaf984b709");
117
118 /// Linux home partition type GUID.
119 ///
120 /// Used by systemd-gpt-auto-generator for automatic /home discovery.
121 ///
122 /// ```text
123 /// 933ac7e1-2eb4-4f13-b844-0e14e2aef915
124 /// ```
125 pub const GPT_LINUX_HOME: Self = uuid!("933ac7e1-2eb4-4f13-b844-0e14e2aef915");
126
127 /// Microsoft Basic Data partition type GUID.
128 ///
129 /// Used for NTFS and FAT partitions on GPT disks.
130 ///
131 /// ```text
132 /// ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
133 /// ```
134 pub const GPT_MS_BASIC_DATA: Self = uuid!("ebd0a0a2-b9e5-4433-87c0-68b6b72699c7");
135
136 // =========================================================================
137 // Microsoft COM
138 // =========================================================================
139
140 /// The `IUnknown` interface GUID.
141 ///
142 /// The fundamental COM interface that all COM objects must implement.
143 ///
144 /// ```text
145 /// 00000000-0000-0000-c000-000000000046
146 /// ```
147 pub const COM_IUNKNOWN: Self = uuid!("00000000-0000-0000-c000-000000000046");
148}
149
150#[cfg(test)]
151mod tests {
152 use crate::UUID;
153
154 #[test]
155 fn nil_constant_matches_nil_method() {
156 assert_eq!(UUID::NIL, UUID::nil());
157 }
158
159 #[test]
160 fn max_constant_matches_max_method() {
161 assert_eq!(UUID::MAX, UUID::max());
162 }
163
164 #[test]
165 fn nil_is_all_zeros() {
166 assert_eq!(
167 UUID::NIL.to_string(),
168 "00000000-0000-0000-0000-000000000000"
169 );
170 }
171
172 #[test]
173 fn max_is_all_ones() {
174 assert_eq!(
175 UUID::MAX.to_string(),
176 "ffffffff-ffff-ffff-ffff-ffffffffffff"
177 );
178 }
179
180 #[test]
181 fn ns_dns_matches_rfc() {
182 assert_eq!(
183 UUID::NS_DNS.to_string(),
184 "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
185 );
186 }
187
188 #[test]
189 fn ns_url_matches_rfc() {
190 assert_eq!(
191 UUID::NS_URL.to_string(),
192 "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
193 );
194 }
195
196 #[test]
197 fn ns_oid_matches_rfc() {
198 assert_eq!(
199 UUID::NS_OID.to_string(),
200 "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
201 );
202 }
203
204 #[test]
205 fn ns_x500_matches_rfc() {
206 assert_eq!(
207 UUID::NS_X500.to_string(),
208 "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
209 );
210 }
211
212 #[test]
213 fn namespaces_are_v1_osf() {
214 assert!(UUID::NS_DNS.is_v1() && UUID::NS_DNS.is_osf());
215 assert!(UUID::NS_URL.is_v1() && UUID::NS_URL.is_osf());
216 assert!(UUID::NS_OID.is_v1() && UUID::NS_OID.is_osf());
217 assert!(UUID::NS_X500.is_v1() && UUID::NS_X500.is_osf());
218 }
219
220 #[test]
221 fn bluetooth_base_matches_spec() {
222 assert_eq!(
223 UUID::BLUETOOTH_BASE.to_string(),
224 "00000000-0000-1000-8000-00805f9b34fb"
225 );
226 }
227
228 #[test]
229 fn gpt_efi_system_matches_spec() {
230 assert_eq!(
231 UUID::GPT_EFI_SYSTEM.to_string(),
232 "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
233 );
234 }
235
236 #[test]
237 fn gpt_linux_fs_matches_spec() {
238 assert_eq!(
239 UUID::GPT_LINUX_FS.to_string(),
240 "0fc63daf-8483-4772-8e79-3d69d8477de4"
241 );
242 }
243
244 #[test]
245 fn gpt_linux_swap_matches_spec() {
246 assert_eq!(
247 UUID::GPT_LINUX_SWAP.to_string(),
248 "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f"
249 );
250 }
251
252 #[test]
253 fn gpt_linux_root_x86_64_matches_spec() {
254 assert_eq!(
255 UUID::GPT_LINUX_ROOT_X86_64.to_string(),
256 "4f68bce3-e8cd-4db1-96e7-fbcaf984b709"
257 );
258 }
259
260 #[test]
261 fn gpt_linux_home_matches_spec() {
262 assert_eq!(
263 UUID::GPT_LINUX_HOME.to_string(),
264 "933ac7e1-2eb4-4f13-b844-0e14e2aef915"
265 );
266 }
267
268 #[test]
269 fn gpt_ms_basic_data_matches_spec() {
270 assert_eq!(
271 UUID::GPT_MS_BASIC_DATA.to_string(),
272 "ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"
273 );
274 }
275
276 #[test]
277 fn com_iunknown_matches_spec() {
278 assert_eq!(
279 UUID::COM_IUNKNOWN.to_string(),
280 "00000000-0000-0000-c000-000000000046"
281 );
282 }
283}