Struct Blob

Source
#[repr(C, packed(1))]
pub struct Blob<T: BlobLayout>(/* private fields */);
Expand description

C-compatible dynamic inline structure.

Can be used to house data with a header structure of a statically known size but with trailing data of size dependent on the header field values.

§Layout

The structure is marked as #[repr(C, packed)] to be layout-compatible with regular byte slice ([u8]) since it’s mostly constructed from Box<[u8]> via C FFI.

It’s worth noting that heap allocation will often align to pointer size, so no unaligned load should happen once the value is constructed from heap-allocated bytes.

Implementations§

Source§

impl Blob<DsaParameter>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_PARAMETER_HEADER, tail: &DsaParameterViewTail<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaParameter>

Source

pub fn prime(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source§

impl Blob<DsaParameterV2>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_PARAMETER_HEADER_V2, tail: &DsaParameterV2ViewTail<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaParameterV2>

Source

pub fn prime(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source§

impl Blob<DhParameter>

Source

pub fn clone_from_parts( header: &BCRYPT_DH_PARAMETER_HEADER, tail: &DhParameterViewTail<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DhParameter>

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source§

impl<T> Blob<T>
where T: BlobLayout + KeyBlob,

Source

pub fn magic(&self) -> ULONG

Source

pub fn blob_type(&self) -> Option<BlobType>

Source

pub fn as_erased(&self) -> &Blob<ErasedKeyBlob>

Source

pub fn try_into<U>(self: Box<Self>) -> Result<Box<Blob<U>>, Box<Self>>
where U: BlobLayout + KeyBlob,

Source§

impl Blob<ErasedKeyBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_KEY_BLOB, tail: &ErasedKeyPayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<ErasedKeyBlob>

Source

pub fn phantom(&self) -> &[u8]

Source§

impl Blob<RsaKeyPublicBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_RSAKEY_BLOB, tail: &RsaKeyPublicPayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<RsaKeyPublicBlob>

Source

pub fn pub_exp(&self) -> &[u8]

Source

pub fn modulus(&self) -> &[u8]

Source§

impl Blob<RsaKeyPrivateBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_RSAKEY_BLOB, tail: &RsaKeyPrivatePayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<RsaKeyPrivateBlob>

Source

pub fn pub_exp(&self) -> &[u8]

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn prime1(&self) -> &[u8]

Source

pub fn prime2(&self) -> &[u8]

Source§

impl Blob<RsaKeyFullPrivateBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_RSAKEY_BLOB, tail: &RsaKeyFullPrivatePayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<RsaKeyFullPrivateBlob>

Source

pub fn pub_exp(&self) -> &[u8]

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn prime1(&self) -> &[u8]

Source

pub fn prime2(&self) -> &[u8]

Source

pub fn exponent1(&self) -> &[u8]

Source

pub fn exponent2(&self) -> &[u8]

Source

pub fn coeff(&self) -> &[u8]

Source

pub fn priv_exp(&self) -> &[u8]

Source§

impl Blob<DhKeyPublicBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_DH_KEY_BLOB, tail: &DhKeyPublicPayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DhKeyPublicBlob>

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source§

impl Blob<DhKeyPrivateBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_DH_KEY_BLOB, tail: &DhKeyPrivatePayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DhKeyPrivateBlob>

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source

pub fn priv_exp(&self) -> &[u8]

Source§

impl Blob<DsaKeyPublicBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_KEY_BLOB, tail: &DsaKeyPublicPayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaKeyPublicBlob>

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source§

impl Blob<DsaKeyPrivateBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_KEY_BLOB, tail: &DsaKeyPrivatePayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaKeyPrivateBlob>

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source

pub fn priv_exp(&self) -> &[u8]

Source§

impl Blob<DsaKeyPublicV2Blob>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_KEY_BLOB_V2, tail: &DsaKeyPublicV2Payload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaKeyPublicV2Blob>

Source

pub fn seed(&self) -> &[u8]

Source

pub fn group(&self) -> &[u8]

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source§

impl Blob<DsaKeyPrivateV2Blob>

Source

pub fn clone_from_parts( header: &BCRYPT_DSA_KEY_BLOB_V2, tail: &DsaKeyPrivateV2Payload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<DsaKeyPrivateV2Blob>

Source

pub fn seed(&self) -> &[u8]

Source

pub fn group(&self) -> &[u8]

Source

pub fn modulus(&self) -> &[u8]

Source

pub fn generator(&self) -> &[u8]

Source

pub fn public(&self) -> &[u8]

Source

pub fn priv_exp(&self) -> &[u8]

Source§

impl Blob<EccKeyPublicBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_ECCKEY_BLOB, tail: &EccKeyPublicPayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<EccKeyPublicBlob>

Source

pub fn x(&self) -> &[u8]

Source

pub fn y(&self) -> &[u8]

Source§

impl Blob<EccKeyPrivateBlob>

Source

pub fn clone_from_parts( header: &BCRYPT_ECCKEY_BLOB, tail: &EccKeyPrivatePayload<'_>, ) -> Box<Self>

Create a [$wrapper_ident] blob instance from its parts.

SAFETY: The header might contain length information about the payload (i.e. the tail argument). An mismatch between the two won’t cause a memory corruption, but it will panic. Careful validation of the arguments must be done to ensure proper behaviour.

Source§

impl Blob<EccKeyPrivateBlob>

Source

pub fn x(&self) -> &[u8]

Source

pub fn y(&self) -> &[u8]

Source

pub fn d(&self) -> &[u8]

Source§

impl<T: BlobLayout> Blob<T>

Source

pub fn header(&self) -> &T::Header

Source

pub fn as_bytes(&self) -> &[u8]

Source

pub fn into_bytes(self: Box<Self>) -> Box<[u8]>

Source

pub fn from_boxed(boxed: Box<[u8]>) -> Box<Self>

Trait Implementations§

Source§

impl<T: BlobLayout> AsBytes for Blob<T>

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn into_bytes(self: Box<Self>) -> Box<[u8]>

Source§

impl<T> AsRef<Blob<ErasedKeyBlob>> for Blob<T>
where T: BlobLayout + KeyBlob,

Source§

fn as_ref(&self) -> &Blob<ErasedKeyBlob>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Blob<ErasedKeyBlob>> for DsaPrivateBlob

Source§

fn as_ref(&self) -> &Blob<ErasedKeyBlob>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Blob<ErasedKeyBlob>> for DsaPublicBlob

Source§

fn as_ref(&self) -> &Blob<ErasedKeyBlob>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: BlobLayout> FromBytes for Blob<T>

Source§

const MIN_LAYOUT: Layout

Specified the minimum layout requirements for the allocation: Read more
Source§

fn from_bytes(bytes: &[u8]) -> &Self

Source§

fn from_boxed(boxed: Box<[u8]>) -> Box<Self>

Auto Trait Implementations§

§

impl<T> Freeze for Blob<T>
where <T as BlobLayout>::Header: Freeze,

§

impl<T> RefUnwindSafe for Blob<T>

§

impl<T> Send for Blob<T>
where <T as BlobLayout>::Header: Send,

§

impl<T> !Sized for Blob<T>

§

impl<T> Sync for Blob<T>
where <T as BlobLayout>::Header: Sync,

§

impl<T> Unpin for Blob<T>
where <T as BlobLayout>::Header: Unpin,

§

impl<T> UnwindSafe for Blob<T>
where <T as BlobLayout>::Header: UnwindSafe,

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