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