devolutions_crypto_wayk/bastion/
mod.rs1pub mod key_derive;
3
4pub mod key_exchange;
6
7pub mod fle;
9
10use std::error::Error as StdError;
11use std::fmt;
12use uuid::Uuid;
13
14#[derive(Debug)]
16pub enum Error {
17 XChaCha20,
18 InvalidSize { got: usize },
19 Base64(base64::DecodeError),
20 Rand(rand::Error),
21 MasterKeyIdMismatch { expected: Uuid, found: Uuid },
22 PadOperation,
23 InvalidMagicNumber,
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 Error::XChaCha20 => write!(f, "XChaCha20 error"),
30 Error::InvalidSize { got } => write!(f, "invalid size: got {}", got),
31 Error::Base64(e) => write!(f, "base64 error: {}", e),
32 Error::Rand(e) => write!(f, "rand error: {}", e),
33 Error::MasterKeyIdMismatch { expected, found } => write!(
34 f,
35 "master key mismatch: expected {} but found {}",
36 expected, found
37 ),
38 Error::PadOperation => write!(f, "pad operation failed"),
39 Error::InvalidMagicNumber => write!(f, "invalid magic number"),
40 }
41 }
42}
43
44impl StdError for Error {}
45
46impl From<rand::Error> for Error {
47 fn from(e: rand::Error) -> Self {
48 Self::Rand(e)
49 }
50}
51
52impl From<base64::DecodeError> for Error {
53 fn from(e: base64::DecodeError) -> Self {
54 Self::Base64(e)
55 }
56}