use crate::traits::Backend;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid auth-bound blob: {reason}")]
Malformed {
reason: &'static str,
},
#[error("unsupported auth-bound blob version: {version}")]
UnsupportedVersion {
version: u8,
},
#[error("the auth-bound blob names an unknown backend: {backend}")]
UnknownBackend {
backend: u8,
},
#[error("the auth-bound blob belongs to backend {actual:?}, but {expected:?} was asked")]
WrongBackend {
expected: Backend,
actual: Backend,
},
#[error("the wrapped payload is {actual} bytes; at most {limit} are allowed")]
PayloadTooLong {
actual: u32,
limit: u32,
},
#[error("the wrapped payload is empty")]
PayloadEmpty,
#[error("the master key must be {expected} bytes, but is {actual} bytes")]
MasterKeyWrongLength {
expected: usize,
actual: usize,
},
#[error("this platform cannot provide an authentication-bound key: {reason}")]
Unavailable {
reason: &'static str,
},
#[error("the platform authentication did not succeed")]
AuthenticationFailed,
#[error("the platform's wrapped payload is invalid: {reason}")]
WrappedPayloadInvalid {
reason: &'static str,
},
#[error("platform operation {operation} failed with code {code}")]
Platform {
operation: &'static str,
code: i32,
},
#[error("cannot obtain secure random bytes from the operating system")]
RandomnessUnavailable,
#[error("the mock payload did not authenticate")]
MockAuthenticationFailed,
}
pub type Result<T> = core::result::Result<T, Error>;