#[cfg(not(target_arch = "wasm32"))]
use tokio_tungstenite::tungstenite;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[cfg(not(target_arch = "wasm32"))]
#[error("WebSocket error: {0}")]
WebSocket(#[from] tungstenite::Error),
#[cfg(target_arch = "wasm32")]
#[error("WebSocket error: {0}")]
WebSocket(String),
#[error("Noise protocol error: {0}")]
Noise(#[from] snow::Error),
#[error("Attestation verification failed: {0}")]
Attestation(String),
#[error("trust_upgrades verification failed: {0}")]
TrustUpgrades(String),
#[error("Attestation nonce mismatch")]
AttestationNonceMismatch,
#[error("PCR mismatch at index {index}")]
PcrMismatch { index: usize },
#[error("Server error for request {id}: {message}")]
ServerError { id: u64, message: String },
#[error("Connection closed")]
ConnectionClosed,
#[error("HTTP parse error: {0}")]
HttpParse(String),
#[error("CBOR error: {0}")]
Cbor(String),
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("Unexpected server message")]
UnexpectedMessage,
#[error("upgrade rejected: server returned status {status}")]
UpgradeFailed { status: u16, head: Vec<u8> },
}
impl From<ciborium::ser::Error<std::io::Error>> for Error {
fn from(e: ciborium::ser::Error<std::io::Error>) -> Self {
Error::Cbor(e.to_string())
}
}
impl From<ciborium::de::Error<std::io::Error>> for Error {
fn from(e: ciborium::de::Error<std::io::Error>) -> Self {
Error::Cbor(e.to_string())
}
}