pub struct Document { /* private fields */ }
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
sourceimpl Document
impl Document
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get the ASN.1 DER-encoded bytes of this document.
sourcepub fn into_secret(self) -> SecretDocument
pub fn into_secret(self) -> SecretDocument
Convert to a SecretDocument
.
sourcepub fn decode_msg<'a, T>(&'a self) -> Result<T, Error> where
T: Decode<'a>,
pub fn decode_msg<'a, T>(&'a self) -> Result<T, Error> where
T: Decode<'a>,
Try to decode the inner ASN.1 DER message contained in this
Document
as the given type.
sourcepub fn encode_msg<T>(msg: &T) -> Result<Document, Error> where
T: Encode,
pub fn encode_msg<T>(msg: &T) -> Result<Document, Error> where
T: Encode,
Encode the provided type as ASN.1 DER, storing the resulting encoded DER
as a Document
.
sourcepub fn from_pem(pem: &str) -> Result<(&str, Document), Error>
pub fn from_pem(pem: &str) -> Result<(&str, Document), Error>
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, Error>
pub fn to_pem(
&self,
label: &'static str,
line_ending: LineEnding
) -> Result<String, Error>
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<Document, Error>
pub fn read_der_file(path: impl AsRef<Path>) -> Result<Document, Error>
Read ASN.1 DER document from a file.
sourcepub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn write_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Write ASN.1 DER document to a file.
sourcepub fn read_pem_file(
path: impl AsRef<Path>
) -> Result<(String, Document), Error>
pub fn read_pem_file(
path: impl AsRef<Path>
) -> Result<(String, Document), Error>
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<(), Error>
pub fn write_pem_file(
&self,
path: impl AsRef<Path>,
label: &'static str,
line_ending: LineEnding
) -> Result<(), Error>
Write PEM-encoded ASN.1 DER document to a file.
Trait Implementations
sourceimpl Encode for Document
impl Encode for Document
sourcefn encoded_len(&self) -> Result<Length, Error>
fn encoded_len(&self) -> Result<Length, Error>
Compute the length of this value in bytes when encoded as ASN.1 DER.
sourcefn encode(&self, writer: &mut dyn Writer) -> Result<(), Error>
fn encode(&self, writer: &mut dyn Writer) -> Result<(), Error>
Encode this value as ASN.1 DER using the provided Writer
.
sourcefn encode_to_slice(&self, buf: &'a mut [u8]) -> Result<&'a [u8], Error>
fn encode_to_slice(&self, buf: &'a mut [u8]) -> Result<&'a [u8], Error>
Encode this value to the provided byte slice, returning a sub-slice containing the encoded message. Read more
sourceimpl TryFrom<&'_ SubjectPublicKeyInfo<'_>> for Document
Available on crate feature alloc
only.
impl TryFrom<&'_ SubjectPublicKeyInfo<'_>> for Document
alloc
only.sourceimpl TryFrom<SubjectPublicKeyInfo<'_>> for Document
Available on crate feature alloc
only.
impl TryFrom<SubjectPublicKeyInfo<'_>> for Document
alloc
only.impl Eq for Document
impl StructuralEq for Document
impl StructuralPartialEq for Document
Auto Trait Implementations
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'a, T> Choice<'a> for T where
T: Decode<'a> + FixedTag,
impl<'a, T> Choice<'a> for T where
T: Decode<'a> + FixedTag,
sourcefn can_decode(tag: Tag) -> bool
fn can_decode(tag: Tag) -> bool
Is the provided Tag
decodable as a variant of this CHOICE
?
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more