Skip to main content

windows_lsa/
types.rs

1//! Public data types shared between the Windows and stub back-ends.
2
3use core::fmt;
4use zeroize::{Zeroize, ZeroizeOnDrop};
5
6/// Windows Locally Unique Identifier — same wire layout as `LUID` /
7/// `LARGE_INTEGER`, kept target-neutral so it appears in the API on every OS.
8#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
9#[repr(C)]
10pub struct Luid {
11    pub low_part: u32,
12    pub high_part: i32,
13}
14
15impl Luid {
16    pub const ZERO: Luid = Luid {
17        low_part: 0,
18        high_part: 0,
19    };
20
21    #[inline]
22    pub const fn new(low_part: u32, high_part: i32) -> Self {
23        Self {
24            low_part,
25            high_part,
26        }
27    }
28
29    #[inline]
30    pub const fn as_u64(self) -> u64 {
31        ((self.high_part as u32 as u64) << 32) | (self.low_part as u64)
32    }
33}
34
35impl fmt::Display for Luid {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        write!(f, "0x{:016x}", self.as_u64())
38    }
39}
40
41/// Identifier returned by `LsaLookupAuthenticationPackage`. Newtype so it
42/// cannot be confused with a raw u32.
43#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
44pub struct AuthPackageId(pub u32);
45
46/// A Kerberos credential blob as accepted by `KerbSubmitTicketMessage` and
47/// returned (in raw ticket form) by `KerbRetrieveTicketMessage`.
48///
49/// `encoded` is treated as opaque bytes by this crate — no ASN.1 parsing is
50/// performed. For `submit_ticket` the caller MUST already have a valid
51/// `KRB-CRED` structure. For values returned by [`crate::retrieve_tgt`] the
52/// bytes are the raw `EncodedTicket` field of `KERB_EXTERNAL_TICKET` (i.e.
53/// the ASN.1-DER `Ticket`, not a full `KRB-CRED`); wrapping that into a
54/// KRB-CRED before it can be re-submitted is outside the current API scope.
55#[derive(Clone, Default, Zeroize, ZeroizeOnDrop)]
56pub struct KrbCred {
57    pub encoded: Vec<u8>,
58}
59
60impl KrbCred {
61    #[inline]
62    pub fn new(encoded: Vec<u8>) -> Self {
63        Self { encoded }
64    }
65
66    #[inline]
67    pub fn as_bytes(&self) -> &[u8] {
68        &self.encoded
69    }
70
71    #[inline]
72    pub fn is_empty(&self) -> bool {
73        self.encoded.is_empty()
74    }
75
76    #[inline]
77    pub fn len(&self) -> usize {
78        self.encoded.len()
79    }
80}
81
82impl fmt::Debug for KrbCred {
83    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84        f.debug_struct("KrbCred")
85            .field("len", &self.encoded.len())
86            .finish_non_exhaustive()
87    }
88}
89
90/// One entry from `KerbQueryTicketCacheMessage`.
91#[derive(Clone, Debug, Default)]
92pub struct TicketCacheInfo {
93    pub server_name: String,
94    pub realm_name: String,
95    pub start_time_ft: i64,
96    pub end_time_ft: i64,
97    pub renew_time_ft: i64,
98    pub encryption_type: i32,
99    pub ticket_flags: u32,
100}