Struct pem_rfc7468::Encoder

source ·
pub struct Encoder<'l, 'o> { /* private fields */ }
Expand description

Buffered PEM encoder.

Stateful buffered encoder type which encodes an input PEM document according to RFC 7468’s “Strict” grammar.

Implementations§

source§

impl<'l, 'o> Encoder<'l, 'o>

source

pub fn new( type_label: &'l str, line_ending: LineEnding, out: &'o mut [u8] ) -> Result<Self>

Create a new PEM Encoder with the default options which writes output into the provided buffer.

Uses the default 64-character line wrapping.

source

pub fn new_wrapped( type_label: &'l str, line_width: usize, line_ending: LineEnding, out: &'o mut [u8] ) -> Result<Self>

Create a new PEM Encoder which wraps at the given line width.

Note that per RFC7468 § 2 encoding PEM with any other wrap width besides 64 is technically non-compliant:

Generators MUST wrap the base64-encoded lines so that each line consists of exactly 64 characters except for the final line, which will encode the remainder of the data (within the 64-character line boundary)

This method is provided with the intended purpose of implementing the OpenSSH private key format, which uses a non-standard wrap width of 70.

source

pub fn type_label(&self) -> &'l str

Get the PEM type label used for this document.

source

pub fn encode(&mut self, input: &[u8]) -> Result<()>

Encode the provided input data.

This method can be called as many times as needed with any sized input to write data encoded data into the output buffer, so long as there is sufficient space in the buffer to handle the resulting Base64 encoded data.

source

pub fn base64_encoder(&mut self) -> &mut Base64Encoder<'o>

Borrow the inner Base64Encoder.

source

pub fn finish(self) -> Result<usize>

Finish encoding PEM, writing the post-encapsulation boundary.

On success, returns the total number of bytes written to the output buffer.

Auto Trait Implementations§

§

impl<'l, 'o> Freeze for Encoder<'l, 'o>

§

impl<'l, 'o> RefUnwindSafe for Encoder<'l, 'o>

§

impl<'l, 'o> Send for Encoder<'l, 'o>

§

impl<'l, 'o> Sync for Encoder<'l, 'o>

§

impl<'l, 'o> Unpin for Encoder<'l, 'o>

§

impl<'l, 'o> !UnwindSafe for Encoder<'l, 'o>

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>,

§

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>,

§

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.