1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use cratewrappers;
use crateSid;
/// Wraps [`GetSidSubAuthority`](https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-getsidsubauthority).
///
/// For a checked version, use [`GetSidSubAuthorityChecked`].
///
/// # Safety
///
/// The `Sid` structure *must* have enough sub authorities. This is *not* checked
/// by this function. Accessing a higher index is undefined behavior.
///
/// ```
/// use windows_permissions::{Sid, wrappers::GetSidSubAuthority};
///
/// let sid = Sid::new([1, 2, 3, 4, 5, 6], &[1, 2]).unwrap();
///
/// unsafe {
/// assert_eq!(*GetSidSubAuthority(&sid, 0), 1);
/// assert_eq!(*GetSidSubAuthority(&sid, 1), 2);
/// }
///
/// // Do not do this! This is undefined behavior!
/// // assert_eq!(GetSidSubAuthority(&sid, 2), None);
/// ```
pub unsafe
/// Wraps [`GetSidSubAuthority`](https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-getsidsubauthority)
/// with a runtime check.
///
/// Checks to ensure that the input SID has enough sub-authorities to defend
/// against undefined behavior. To skip the check, use
/// [`GetSidSubAuthorityChecked`].
///
/// ```
/// use windows_permissions::{Sid, wrappers::GetSidSubAuthorityChecked};
///
/// let sid = Sid::new([1, 2, 3, 4, 5, 6], &[1, 2]).unwrap();
///
/// assert_eq!(GetSidSubAuthorityChecked(&sid, 0), Some(1));
/// assert_eq!(GetSidSubAuthorityChecked(&sid, 1), Some(2));
/// assert_eq!(GetSidSubAuthorityChecked(&sid, 2), None);
/// ```