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>
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)>
Available on crate feature pem
only.
pub fn from_pem(pem: &str) -> Result<(&str, Self)>
pem
only.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>
Available on crate feature pem
only.
pub fn to_pem( &self, label: &'static str, line_ending: LineEnding ) -> Result<String>
pem
only.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>
Available on crate feature std
only.
pub fn read_der_file(path: impl AsRef<Path>) -> Result<Self>
std
only.Read ASN.1 DER document from a file.
sourcepub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<()>
Available on crate feature std
only.
pub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<()>
std
only.Write ASN.1 DER document to a file.
sourcepub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self)>
Available on crate features pem
and std
only.
pub fn read_pem_file(path: impl AsRef<Path>) -> Result<(String, Self)>
pem
and std
only.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<()>
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<()>
pem
and std
only.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
.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.