sheave_core/handlers/
inconsistent_sha.rs

1use std::{
2    error::Error,
3    fmt::{
4        Display,
5        Formatter,
6        Result as FormatResult
7    },
8    io::{
9        Error as IOError,
10        ErrorKind
11    }
12};
13
14/// Tells that either digests or signatures is inconsistent in the handshake step.
15#[derive(Debug)]
16pub struct InconsistentSha(Vec<u8>);
17
18impl<'a> InconsistentSha {
19    /// Constructs this error.
20    pub fn new(sha: Vec<u8>) -> Self {
21        Self(sha)
22    }
23}
24
25impl Display for InconsistentSha {
26    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
27        writeln!(f, "Invalid SHA digest/signature: {:?}", self.0)
28    }
29}
30
31impl Error for InconsistentSha {}
32
33/// A utility function for constructing an `InconsistentSha` error.
34pub fn inconsistent_sha(sha: Vec<u8>) -> IOError {
35    IOError::new(
36        ErrorKind::InvalidData,
37        InconsistentSha(sha)
38    )
39}