pub trait ToDer where
Self: DynTagged, {
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>;
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
fn to_der_len(&self) -> Result<usize>
fn to_der_len(&self) -> Result<usize>
Get the length of the object, when encoded
fn 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.
fn 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
fn 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>
.
fn 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.
fn 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]);
fn 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.