pub struct Document {
    der_bytes: Vec<u8>,
    length: Length,
}Expand description
ASN.1 DER-encoded document.
This type wraps an encoded ASN.1 DER message. The document checked to
ensure it contains a valid DER-encoded SEQUENCE.
It implements common functionality related to encoding/decoding such documents, such as PEM encapsulation as well as reading/writing documents from/to the filesystem.
The SecretDocument provides a wrapper for this type with additional
hardening applied.
Fields§
§der_bytes: Vec<u8>ASN.1 DER encoded bytes.
length: LengthLength of this document.
Implementations§
Source§impl Document
 
impl Document
Sourcepub fn into_secret(self) -> SecretDocument
 
pub fn into_secret(self) -> SecretDocument
Convert to a SecretDocument.
Sourcepub fn decode_msg<'a, T: Decode<'a>>(&'a self) -> Result<T>
 
pub fn decode_msg<'a, T: Decode<'a>>(&'a self) -> Result<T>
Try to decode the inner ASN.1 DER message contained in this
Document as the given type.
Sourcepub fn encode_msg<T: Encode>(msg: &T) -> Result<Self>
 
pub fn encode_msg<T: Encode>(msg: &T) -> Result<Self>
Encode the provided type as ASN.1 DER, storing the resulting encoded DER
as a Document.
Sourcepub fn from_pem(pem: &str) -> Result<(&str, Self)>
 
pub fn from_pem(pem: &str) -> Result<(&str, Self)>
Decode ASN.1 DER document from PEM.
Returns the PEM label and decoded Document on success.
Sourcepub fn to_pem(
    &self,
    label: &'static str,
    line_ending: LineEnding,
) -> Result<String>
 
pub fn to_pem( &self, label: &'static str, line_ending: LineEnding, ) -> Result<String>
Encode ASN.1 DER document as a PEM string with encapsulation boundaries
containing the provided PEM type label (e.g. CERTIFICATE).
Sourcepub fn read_der_file(path: impl AsRef<Path>) -> Result<Self>
 
pub fn read_der_file(path: impl AsRef<Path>) -> Result<Self>
Read ASN.1 DER document from a file.
Sourcepub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<()>
 
pub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<()>
Write ASN.1 DER document to a file.
Sourcepub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self)>
 
pub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self)>
Read PEM-encoded ASN.1 DER document from a file.
Sourcepub fn write_pem_file(
    &self,
    path: impl AsRef<Path>,
    label: &'static str,
    line_ending: LineEnding,
) -> Result<()>
 
pub fn write_pem_file( &self, path: impl AsRef<Path>, label: &'static str, line_ending: LineEnding, ) -> Result<()>
Write PEM-encoded ASN.1 DER document to a file.
Trait Implementations§
Source§impl Encode for Document
 
impl Encode for Document
Source§fn encoded_len(&self) -> Result<Length>
 
fn encoded_len(&self) -> Result<Length>
Source§fn encode(&self, writer: &mut impl Writer) -> Result<()>
 
fn encode(&self, writer: &mut impl Writer) -> Result<()>
Writer.