rocket::mtls::oid::asn1_rs

Trait ToDer

Source
pub trait ToDer: DynTagged {
    // Required methods
    fn to_der_len(&self) -> Result<usize, Error>;
    fn write_der_header(
        &self,
        writer: &mut dyn Write,
    ) -> Result<usize, SerializeError>;
    fn write_der_content(
        &self,
        writer: &mut dyn Write,
    ) -> Result<usize, SerializeError>;

    // Provided methods
    fn to_der_vec(&self) -> Result<Vec<u8>, SerializeError> { ... }
    fn to_der_vec_raw(&self) -> Result<Vec<u8>, SerializeError> { ... }
    fn write_der(&self, writer: &mut dyn Write) -> Result<usize, SerializeError> { ... }
    fn write_der_raw(
        &self,
        writer: &mut dyn Write,
    ) -> Result<usize, SerializeError> { ... }
}
Available on crate feature mtls only.
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, Error>

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

Source

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

Attempt to write the DER header to this writer.

Source

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

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

Provided Methods§

Source

fn to_der_vec(&self) -> Result<Vec<u8>, SerializeError>

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

Source

fn to_der_vec_raw(&self) -> Result<Vec<u8>, SerializeError>

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) -> Result<usize, SerializeError>

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) -> Result<usize, SerializeError>

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

Source§

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

Source§

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

Source§

impl ToDer for (Class, bool, Tag)

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for bool

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for i8

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for i16

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for i32

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for i64

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for i128

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for u8

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for u16

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for u32

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for u64

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for u128

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ToDer for ()

Source§

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

Source§

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

Source§

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

Source§

impl<'a> ToDer for &'a str

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl ToDer for Length

Source§

impl ToDer for Real

Source§

impl ToDer for String

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 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 ToDer for Oid<'_>

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 Option<T>
where T: ToDer,

Source§

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

Source§

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

Source§

impl<T> ToDer for Vec<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,