Encapsulation

Struct Encapsulation 

Source
struct Encapsulation<'a> {
    label: &'a str,
    encapsulated_text: &'a [u8],
}
Expand description

PEM encapsulation parser.

This parser performs an initial pass over the data, locating the pre-encapsulation (---BEGIN [...]---) and post-encapsulation (---END [...]) boundaries while attempting to avoid branching on the potentially secret Base64-encoded data encapsulated between the two boundaries.

It only supports a single encapsulated message at present. Future work could potentially include extending it provide an iterator over a series of encapsulated messages.

Fields§

§label: &'a str

Type label extracted from the pre/post-encapsulation boundaries.

From RFC 7468 Section 2:

The type of data encoded is labeled depending on the type label in the “—–BEGIN “ line (pre-encapsulation boundary). For example, the line may be “—–BEGIN CERTIFICATE—–” to indicate that the content is a PKIX certificate (see further below). Generators MUST put the same label on the “—–END “ line (post-encapsulation boundary) as the corresponding “—–BEGIN “ line. Labels are formally case-sensitive, uppercase, and comprised of zero or more characters; they do not contain consecutive spaces or hyphen-minuses, nor do they contain spaces or hyphen-minuses at either end. Parsers MAY disregard the label in the post-encapsulation boundary instead of signaling an error if there is a label mismatch: some extant implementations require the labels to match; others do not.

§encapsulated_text: &'a [u8]

Encapsulated text portion contained between the boundaries.

This data should be encoded as Base64, however this type performs no validation of it so it can be handled in constant-time.

Implementations§

Source§

impl<'a> Encapsulation<'a>

Source

pub fn parse(data: &'a [u8]) -> Result<Self>

Parse the type label and encapsulated text from between the pre/post-encapsulation boundaries.

Source

pub fn label(self) -> &'a str

Get the label parsed from the encapsulation boundaries.

Trait Implementations§

Source§

impl<'a> Clone for Encapsulation<'a>

Source§

fn clone(&self) -> Encapsulation<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Encapsulation<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> TryFrom<&'a [u8]> for Encapsulation<'a>

Source§

type Error = Error

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

fn try_from(bytes: &'a [u8]) -> Result<Self>

Performs the conversion.
Source§

impl<'a> Copy for Encapsulation<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Encapsulation<'a>

§

impl<'a> RefUnwindSafe for Encapsulation<'a>

§

impl<'a> Send for Encapsulation<'a>

§

impl<'a> Sync for Encapsulation<'a>

§

impl<'a> Unpin for Encapsulation<'a>

§

impl<'a> UnwindSafe for Encapsulation<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.