Skip to main content

core_crypto/error/
tls.rs

1/// A TLS codec operation failed, but we captured some context about which item it was coding
2#[derive(Debug, thiserror::Error)]
3#[error("TLS {direction} {item}")]
4pub struct TlsCodecError {
5    direction: &'static str,
6    item: &'static str,
7    #[source]
8    source: tls_codec::Error,
9}
10
11impl TlsCodecError {
12    /// Wrap a failure to TLS-serialize `item`
13    pub fn serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
14        move |source| Self {
15            direction: "serializing",
16            item,
17            source,
18        }
19    }
20
21    /// Wrap a failure to TLS-deserialize `item`
22    pub fn deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
23        move |source| Self {
24            direction: "deserializing",
25            item,
26            source,
27        }
28    }
29}