1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use crate::crypto::CryptoError; pub type Result<T> = std::result::Result<T, Error>; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Unparseable Hawk header: {0}")] HeaderParseError(String), #[error("Invalid url: {0}")] InvalidUrl(String), #[error("Missing `ts` attribute in Hawk header")] MissingTs, #[error("Missing `nonce` attribute in Hawk header")] MissingNonce, #[error("{0}")] InvalidBewit(#[source] InvalidBewit), #[error("{0}")] Io(#[source] std::io::Error), #[error("Base64 Decode error: {0}")] Decode(#[source] base64::DecodeError), #[error("Crypto error: {0}")] Crypto(#[source] CryptoError), } #[derive(thiserror::Error, Debug, PartialEq)] pub enum InvalidBewit { #[error("Multiple bewits in URL")] Multiple, #[error("Invalid bewit format")] Format, #[error("Invalid bewit id")] Id, #[error("Invalid bewit exp")] Exp, #[error("Invalid bewit mac")] Mac, #[error("Invalid bewit ext")] Ext, } impl From<base64::DecodeError> for Error { fn from(e: base64::DecodeError) -> Self { Error::Decode(e) } } impl From<std::io::Error> for Error { fn from(e: std::io::Error) -> Self { Error::Io(e) } } impl From<CryptoError> for Error { fn from(e: CryptoError) -> Self { Error::Crypto(e) } } impl From<InvalidBewit> for Error { fn from(e: InvalidBewit) -> Self { Error::InvalidBewit(e) } }