pub struct Document { /* private fields */ }alloc only.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.
Implementations§
Source§impl Document
impl Document
Sourcepub fn into_secret(self) -> SecretDocument
Available on crate feature zeroize only.
pub fn into_secret(self) -> SecretDocument
zeroize only.Convert to a SecretDocument.
Sourcepub fn decode_msg<'a, T: Decode<'a>>(&'a self) -> Result<T, T::Error>
pub fn decode_msg<'a, T: Decode<'a>>(&'a self) -> Result<T, T::Error>
Sourcepub fn to_pem(
&self,
label: &'static str,
line_ending: LineEnding,
) -> Result<String, Error>
Available on crate feature pem only.
pub fn to_pem( &self, label: &'static str, line_ending: LineEnding, ) -> Result<String, Error>
pem only.Encode ASN.1 DER document as a PEM string with encapsulation boundaries
containing the provided PEM type label (e.g. CERTIFICATE).
§Errors
If an encoding error occurred.
Sourcepub fn read_der_file(path: impl AsRef<Path>) -> Result<Self, Error>
Available on crate feature std only.
pub fn read_der_file(path: impl AsRef<Path>) -> Result<Self, Error>
std only.Read ASN.1 DER document from a file.
§Errors
If the file could not be read, or a decoding error occurred.
Sourcepub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Available on crate feature std only.
pub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
std only.Write ASN.1 DER document to a file.
§Errors
If the file could not be written to, or an encoding error occurred.
Sourcepub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self), Error>
Available on crate features pem and std only.
pub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self), Error>
pem and std only.Read PEM-encoded ASN.1 DER document from a file.
§Errors
If the file could not be read, or a decoding error occurred.
Sourcepub fn write_pem_file(
&self,
path: impl AsRef<Path>,
label: &'static str,
line_ending: LineEnding,
) -> Result<(), Error>
Available on crate features pem and std only.
pub fn write_pem_file( &self, path: impl AsRef<Path>, label: &'static str, line_ending: LineEnding, ) -> Result<(), Error>
pem and std only.Write PEM-encoded ASN.1 DER document to a file.
§Errors
If the file could not be written to, or an encoding error occurred.
Trait Implementations§
Source§impl<'a> Decode<'a> for Document
impl<'a> Decode<'a> for Document
Source§fn decode<R: Reader<'a>>(reader: &mut R) -> Result<Document, Error>
fn decode<R: Reader<'a>>(reader: &mut R) -> Result<Document, Error>
Source§fn from_ber(bytes: &'a [u8]) -> Result<Self, Self::Error>
fn from_ber(bytes: &'a [u8]) -> Result<Self, Self::Error>
ber only.Self from the provided BER-encoded byte slice. Read moreSource§impl Encode for Document
impl Encode for Document
Source§fn encoded_len(&self) -> Result<Length, Error>
fn encoded_len(&self) -> Result<Length, Error>
Source§fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
Source§impl From<Document> for SecretDocument
Available on crate feature zeroize only.
impl From<Document> for SecretDocument
zeroize only.