pub struct Encoder<'a> { /* private fields */ }
Expand description
DER encoder.
Implementations§
source§impl<'a> Encoder<'a>
impl<'a> Encoder<'a>
sourcepub fn new(bytes: &'a mut [u8]) -> Self
pub fn new(bytes: &'a mut [u8]) -> Self
Create a new encoder with the given byte slice as a backing buffer.
sourcepub fn encode<T: Encodable>(&mut self, encodable: &T) -> Result<()>
pub fn encode<T: Encodable>(&mut self, encodable: &T) -> Result<()>
Encode a value which impls the Encodable
trait.
sourcepub fn error<T>(&mut self, kind: ErrorKind) -> Result<T>
pub fn error<T>(&mut self, kind: ErrorKind) -> Result<T>
Return an error with the given ErrorKind
, annotating it with
context about where the error occurred.
sourcepub fn value_error(&mut self, tag: Tag) -> Error
pub fn value_error(&mut self, tag: Tag) -> Error
Return an error for an invalid value with the given tag.
sourcepub fn finish(self) -> Result<&'a [u8]>
pub fn finish(self) -> Result<&'a [u8]>
Finish encoding to the buffer, returning a slice containing the data written to the buffer.
sourcepub fn bit_string(&mut self, value: impl TryInto<BitString<'a>>) -> Result<()>
pub fn bit_string(&mut self, value: impl TryInto<BitString<'a>>) -> Result<()>
Encode the provided value as an ASN.1 BIT STRING
.
sourcepub fn context_specific<T>(
&mut self,
tag_number: TagNumber,
tag_mode: TagMode,
value: &T,
) -> Result<()>where
T: EncodeValue + Tagged,
pub fn context_specific<T>(
&mut self,
tag_number: TagNumber,
tag_mode: TagMode,
value: &T,
) -> Result<()>where
T: EncodeValue + Tagged,
Encode a CONTEXT-SPECIFIC
field with EXPLICIT
tagging.
sourcepub fn generalized_time(
&mut self,
value: impl TryInto<GeneralizedTime>,
) -> Result<()>
pub fn generalized_time( &mut self, value: impl TryInto<GeneralizedTime>, ) -> Result<()>
Encode the provided value as an ASN.1 GeneralizedTime
sourcepub fn ia5_string(&mut self, value: impl TryInto<Ia5String<'a>>) -> Result<()>
pub fn ia5_string(&mut self, value: impl TryInto<Ia5String<'a>>) -> Result<()>
Encode the provided value as an ASN.1 IA5String
.
sourcepub fn octet_string(
&mut self,
value: impl TryInto<OctetString<'a>>,
) -> Result<()>
pub fn octet_string( &mut self, value: impl TryInto<OctetString<'a>>, ) -> Result<()>
Encode the provided value as an ASN.1 OCTET STRING
sourcepub fn oid(&mut self, value: impl TryInto<ObjectIdentifier>) -> Result<()>
pub fn oid(&mut self, value: impl TryInto<ObjectIdentifier>) -> Result<()>
Encode an ASN.1 ObjectIdentifier
sourcepub fn printable_string(
&mut self,
value: impl TryInto<PrintableString<'a>>,
) -> Result<()>
pub fn printable_string( &mut self, value: impl TryInto<PrintableString<'a>>, ) -> Result<()>
Encode the provided value as an ASN.1 PrintableString
sourcepub fn sequence<F>(&mut self, length: Length, f: F) -> Result<()>
pub fn sequence<F>(&mut self, length: Length, f: F) -> Result<()>
Encode an ASN.1 SEQUENCE
of the given length.
Spawns a nested Encoder
which is expected to be exactly the
specified length upon completion.
sourcepub fn utc_time(&mut self, value: impl TryInto<UtcTime>) -> Result<()>
pub fn utc_time(&mut self, value: impl TryInto<UtcTime>) -> Result<()>
Encode the provided value as an ASN.1 UTCTime
sourcepub fn utf8_string(&mut self, value: impl TryInto<Utf8String<'a>>) -> Result<()>
pub fn utf8_string(&mut self, value: impl TryInto<Utf8String<'a>>) -> Result<()>
Encode the provided value as an ASN.1 Utf8String