1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use bytes::Bytes;
use dcbor::prelude::*;
use anyhow::{Error, Result};

use crate::Envelope;

impl TryFrom<Envelope> for Bytes {
    type Error = Error;

    fn try_from(envelope: Envelope) -> Result<Self> {
        envelope.try_leaf()?.try_into()
    }
}

impl Envelope {
    pub fn try_from_cbor(cbor: CBOR) -> Result<Self> {
        cbor.try_into()
    }

    pub fn try_from_cbor_data(data: Bytes) -> Result<Self> {
        let cbor = CBOR::try_from_data(data)?;
        Self::try_from_cbor(cbor)
    }
}