Skip to main content

DerWriter

Struct DerWriter 

Source
pub struct DerWriter<'a> { /* private fields */ }
Available on crate feature rustcrypto only.
Expand description

A DER writer that fills its buffer from the end backwards, so that a length is always known by the time its header is written.

Implementations§

Source§

impl<'a> DerWriter<'a>

Source

pub fn new(buf: &'a mut [u8]) -> Self

Starts writing at the end of buf.

Source

pub const fn len(&self) -> usize

How many octets have been written.

Source

pub const fn is_empty(&self) -> bool

Whether nothing has been written.

Source

pub fn finish(self) -> &'a [u8] ⓘ

Everything written, in the right order — the tail of the buffer.

Source

pub const fn mark(&self) -> usize

The current position, to be passed to DerWriter::header once an element’s content has been written.

Source

pub fn byte(&mut self, value: u8) -> Result<()>

Prepends one octet.

Source

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

Prepends a slice.

Source

pub fn header(&mut self, tag: u8, mark: usize) -> Result<()>

Writes an identifier octet and the definite length of everything written since mark, in DER’s minimal form.

Source

pub fn primitive(&mut self, tag: u8, content: &[u8]) -> Result<()>

Writes a complete primitive element.

Source

pub fn oid_with_arc(&mut self, prefix: &[u8], arc: u8) -> Result<()>

Writes an OID whose content is a prefix plus one final arc below 128.

Source

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

Writes a BIT STRING whose content is whole octets — a public key or a signature.

Source

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

Writes a fixed-width big-endian scalar as an INTEGER: leading zeros dropped, and one 0x00 put back if the top bit would otherwise make it negative.

Source

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

Writes an AlgorithmIdentifier with no parameters — SEQUENCE { OID }.

ecdsa-with-SHA256 and sha256 both take this form. An AlgorithmIdentifier with a spurious NULL here would hash differently and fail every signature.

Source

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

Writes a SubjectPublicKeyInfo for an uncompressed P-256 point.

Source

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

Writes an ECDSA-Sig-Value — SEQUENCE { r INTEGER, s INTEGER } — from the fixed-width r || s that Core §3.5.3 uses.

Trait Implementations§

Source§

impl<'a> Debug for DerWriter<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for DerWriter<'a>

§

impl<'a> Forget for DerWriter<'a>

§

impl<'a> Freeze for DerWriter<'a>

§

impl<'a> Move for DerWriter<'a>

§

impl<'a> RefUnwindSafe for DerWriter<'a>

§

impl<'a> Send for DerWriter<'a>

§

impl<'a> Sync for DerWriter<'a>

§

impl<'a> Unpin for DerWriter<'a>

§

impl<'a> UnsafeUnpin for DerWriter<'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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.