Skip to content

Commit

Permalink
Added the ability to create a DerObject directly from a `DerEncodab…
Browse files Browse the repository at this point in the history
  • Loading branch information
KizzyCode committed Mar 18, 2021
1 parent 70f0e91 commit b9ccb57
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/typed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ impl<'a> DerDecodable<'a> for DerObject<'a> {
pub trait DerEncodable: Sized {
/// Encodes `self` into `sink`
fn encode<S: Sink>(&self, sink: &mut S) -> Result<(), Asn1DerError>;

/// Creates an DER object from an encodable type
#[cfg_attr(feature = "no_panic", no_panic::no_panic)]
fn der_object<'a, S: Sink + Into<&'a[u8]>>(&self, mut sink: S) -> Result<DerObject<'a>, Asn1DerError> {
self.encode(&mut sink).propagate(e!("Failed to encode object"))?;
DerObject::decode(sink.into()).propagate("Failed to load constructed object")
}
}
impl<'a> DerEncodable for DerObject<'a> {
#[cfg_attr(feature = "no_panic", no_panic::no_panic)]
Expand Down

0 comments on commit b9ccb57

Please sign in to comment.