Skip to main content

BinaryPayload

Struct BinaryPayload 

Source
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: u8

A 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

Source

pub const MAX_SIZE: usize

The most data it’s possible to put into a BinaryPayload.

Source

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.

Source

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.

Source

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.
Source

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.
Source

pub unsafe fn zero(ptr: *mut Self)

Zeroes out the data of this payload.

§Safety
  • The pointer must point to a valid BinaryPayload.
  • The binary payload must not be used in the future, since its length metadata is gone and so its buffer is unknown.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.