pub struct BinaryPayload {
pub total_bytes_u32be: [u8; 4],
pub data_type: u8,
pub _marker: PhantomData<PhantomPinned>,
}Expand description
The structure of the “binary message” payload for the PAM_BINARY_PROMPT
extension from Linux-PAM.
Fields§
§total_bytes_u32be: [u8; 4]The total byte size of the message, including this header, as u32 in network byte order (big endian).
data_type: u8A tag used to provide some kind of hint as to what the data is. Its meaning is undefined.
_marker: PhantomData<PhantomPinned>Where the data itself would start, used as a marker to make this
not Unpin (since it is effectively an intrusive data structure
pointing to immediately after itself).
Implementations§
Source§impl BinaryPayload
impl BinaryPayload
Sourcepub const MAX_SIZE: usize
pub const MAX_SIZE: usize
The most data it’s possible to put into a BinaryPayload.
Sourcepub fn fill(buf: &mut [u8], data: &[u8], data_type: u8)
pub fn fill(buf: &mut [u8], data: &[u8], data_type: u8)
Fills in the provided buffer with the given data.
This uses copy_from_slice internally,
so buf must be exactly 5 bytes longer than data, or this function
will panic.
Sourcepub unsafe fn total_bytes(this: *const Self) -> usize
pub unsafe fn total_bytes(this: *const Self) -> usize
The total storage needed for the message, including header.
§Safety
The pointer must point to a valid BinaryPayload.
Sourcepub unsafe fn buffer_of<'a>(ptr: *const Self) -> &'a [u8] ⓘ
pub unsafe fn buffer_of<'a>(ptr: *const Self) -> &'a [u8] ⓘ
Gets the total byte buffer of the BinaryMessage stored at the pointer.
The returned data slice is borrowed from where the pointer points to.
§Safety
- The pointer must point to a valid
BinaryPayload. - The borrowed data must not outlive the pointer’s validity.
Sourcepub unsafe fn contents<'a>(ptr: *const Self) -> (&'a [u8], u8)
pub unsafe fn contents<'a>(ptr: *const Self) -> (&'a [u8], u8)
Gets the contents of the BinaryMessage stored at the given pointer.
The returned data slice is borrowed from where the pointer points to. This is a cheap operation and doesn’t do any copying.
We don’t take a &self reference here because accessing beyond
the range of the Self data (i.e., beyond the 5 bytes of self)
is undefined behavior. Instead, you have to pass a raw pointer
directly to the data.
§Safety
- The pointer must point to a valid
BinaryPayload. - The borrowed data must not outlive the pointer’s validity.