Trait asn1_rs::ToDer

source ·
pub trait ToDer
where Self: DynTagged,
{ // Required methods fn to_der_len(&self) -> Result<usize>; fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>; fn write_der_content( &self, writer: &mut dyn Write, ) -> SerializeResult<usize>; // Provided methods fn to_der_vec(&self) -> SerializeResult<Vec<u8>> { ... } fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>> { ... } fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize> { ... } fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize> { ... } }
Expand description

Common trait for all objects that can be encoded using the DER representation

§Examples

Objects from this crate can be encoded as DER:

use asn1_rs::{Integer, ToDer};

let int = Integer::from(4u32);
let mut writer = Vec::new();
let sz = int.write_der(&mut writer).expect("serialization failed");

assert_eq!(&writer, &[0x02, 0x01, 0x04]);

Many of the primitive types can also directly be encoded as DER:

use asn1_rs::ToDer;

let mut writer = Vec::new();
let sz = 4.write_der(&mut writer).expect("serialization failed");

assert_eq!(&writer, &[0x02, 0x01, 0x04]);

Required Methods§

source

fn to_der_len(&self) -> Result<usize>

Get the length of the object (including the header), when encoded

source

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER header to this writer.

source

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER content (all except header) to this writer.

Provided Methods§

source

fn to_der_vec(&self) -> SerializeResult<Vec<u8>>

Write the DER encoded representation to a newly allocated Vec<u8>.

source

fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>>

Similar to using to_vec, but uses provided values without changes. This can generate an invalid encoding for a DER object.

source

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER encoded representation (header and content) into this writer.

§Examples
use asn1_rs::{Integer, ToDer};

let int = Integer::from(4u32);
let mut writer = Vec::new();
let sz = int.write_der(&mut writer).expect("serialization failed");

assert_eq!(&writer, &[0x02, 0x01, 0x04]);
source

fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Similar to using to_der, but uses provided values without changes. This can generate an invalid encoding for a DER object.

Implementations on Foreign Types§

source§

impl ToDer for &[u8]

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for (Class, bool, Tag)

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, _writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for bool

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for i8

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for i16

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for i32

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for i64

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for i128

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for u8

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for u16

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for u32

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for u64

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for u128

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for ()

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, _writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl ToDer for String

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<'a> ToDer for &'a str

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<'a, T> ToDer for &'a T
where T: ToDer, &'a T: DynTagged,

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<T> ToDer for Option<T>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<T> ToDer for BTreeSet<T>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<T> ToDer for Vec<T>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

impl<T> ToDer for HashSet<T>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Implementors§

source§

impl ToDer for Length

source§

impl ToDer for Real

source§

impl ToDer for Any<'_>

source§

impl ToDer for BitString<'_>

source§

impl ToDer for BmpString<'_>

source§

impl ToDer for Boolean

source§

impl ToDer for Enumerated

source§

impl ToDer for GeneralString<'_>

source§

impl ToDer for GeneralizedTime

source§

impl ToDer for GraphicString<'_>

source§

impl ToDer for Header<'_>

source§

impl ToDer for Ia5String<'_>

source§

impl ToDer for Integer<'_>

source§

impl ToDer for Null

source§

impl ToDer for NumericString<'_>

source§

impl ToDer for ObjectDescriptor<'_>

source§

impl ToDer for OctetString<'_>

source§

impl ToDer for Oid<'_>

source§

impl ToDer for PrintableString<'_>

source§

impl ToDer for Sequence<'_>

source§

impl ToDer for Set<'_>

source§

impl ToDer for TeletexString<'_>

source§

impl ToDer for UniversalString<'_>

source§

impl ToDer for UtcTime

source§

impl ToDer for Utf8String<'_>

source§

impl ToDer for VideotexString<'_>

source§

impl ToDer for VisibleString<'_>

source§

impl<'a, T> ToDer for TaggedParser<'a, Explicit, T>
where T: ToDer,

source§

impl<'a, T> ToDer for TaggedParser<'a, Implicit, T>
where T: ToDer,

source§

impl<T> ToDer for SequenceOf<T>
where T: ToDer,

source§

impl<T> ToDer for SetOf<T>
where T: ToDer,

source§

impl<T, E, const CLASS: u8, const TAG: u32> ToDer for TaggedValue<T, E, Explicit, CLASS, TAG>
where T: ToDer,

source§

impl<T, E, const CLASS: u8, const TAG: u32> ToDer for TaggedValue<T, E, Implicit, CLASS, TAG>
where T: ToDer,