Trait der::Document

source ·
pub trait Document<'a>: AsRef<[u8]> + Sized + TryFrom<Vec<u8>, Error = Error> {
    type Message: Decodable<'a> + Encodable + Sized;

    const SENSITIVE: bool;

    // Provided methods
    fn as_der(&self) -> &[u8] { ... }
    fn to_der(&self) -> Box<[u8]> { ... }
    fn decode(&'a self) -> Self::Message { ... }
    fn from_der(bytes: &[u8]) -> Result<Self> { ... }
    fn from_msg(msg: &Self::Message) -> Result<Self> { ... }
    fn from_pem(s: &str) -> Result<Self>
       where Self: PemLabel { ... }
    fn to_pem(&self, line_ending: LineEnding) -> Result<String>
       where Self: PemLabel { ... }
Expand description

ASN.1 DER-encoded document.

This trait is intended to impl on types which contain an ASN.1 DER-encoded document which is guaranteed to encode as the associated Message type.

It implements common functionality related to encoding/decoding such documents, such as PEM encapsulation as well as reading/writing documents from/to the filesystem.

Required Associated Types§


type Message: Decodable<'a> + Encodable + Sized

ASN.1 message type this document decodes to.

Required Associated Constants§


const SENSITIVE: bool

Does this type contain potentially sensitive data?

This enables hardened file permissions when persisting data to disk.

Provided Methods§


fn as_der(&self) -> &[u8]

Borrow the inner serialized bytes of this document.


fn to_der(&self) -> Box<[u8]>

Return an allocated ASN.1 DER serialization as a boxed slice.


fn decode(&'a self) -> Self::Message

Decode this document as ASN.1 DER.


fn from_der(bytes: &[u8]) -> Result<Self>

Create a new document from the provided ASN.1 DER bytes.


fn from_msg(msg: &Self::Message) -> Result<Self>

Encode the provided type as ASN.1 DER.


fn from_pem(s: &str) -> Result<Self>where Self: PemLabel,

Decode ASN.1 DER document from PEM.


fn to_pem(&self, line_ending: LineEnding) -> Result<String>where Self: PemLabel,

Encode ASN.1 DER document as a PEM string.