use affinidi_tsp::MessageType;
use thiserror::Error;
use trust_tasks_rs::RejectReason;
#[derive(Debug, Error)]
pub enum TspError {
#[error("TSP error: {0}")]
Upstream(#[from] affinidi_tsp::TspError),
#[error("unsupported TSP carriage: only Direct is handled (got {0:?})")]
UnsupportedCarriage(MessageType),
#[error("claimed sender VID `{claimed}` does not match the verified sender `{verified}`")]
SenderMismatch {
claimed: String,
verified: String,
},
#[error("unexpected envelope type: {0}")]
WrongEnvelopeType(String),
#[error("payload did not parse as a Trust Task envelope: {0}")]
InvalidBody(serde_json::Error),
#[error("could not serialise TrustTask for the envelope: {0}")]
SerialiseBody(serde_json::Error),
}
impl TspError {
pub fn into_reject_reason(self) -> RejectReason {
RejectReason::MalformedRequest {
reason: self.to_string(),
}
}
}