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> { ... }
}
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§
sourcefn to_der_len(&self) -> Result<usize, Error>
fn to_der_len(&self) -> Result<usize, Error>
Get the length of the object (including the header), when encoded
sourcefn write_der_header(
&self,
writer: &mut dyn Write,
) -> Result<usize, SerializeError>
fn write_der_header( &self, writer: &mut dyn Write, ) -> Result<usize, SerializeError>
Attempt to write the DER header to this writer.
sourcefn write_der_content(
&self,
writer: &mut dyn Write,
) -> Result<usize, SerializeError>
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§
sourcefn to_der_vec(&self) -> Result<Vec<u8>, SerializeError>
fn to_der_vec(&self) -> Result<Vec<u8>, SerializeError>
Write the DER encoded representation to a newly allocated Vec<u8>
.
sourcefn to_der_vec_raw(&self) -> Result<Vec<u8>, SerializeError>
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.
sourcefn write_der(&self, writer: &mut dyn Write) -> Result<usize, SerializeError>
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]);
sourcefn write_der_raw(&self, writer: &mut dyn Write) -> Result<usize, SerializeError>
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.