extern crate alloc;
use alloc::string::{String, ToString};
use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq)]
pub enum SigError {
#[error("key generation failed: {0}")]
KeyGeneration(String),
#[error("signing failed: {0}")]
Signing(String),
#[error("signature verification failed")]
VerificationFailed,
#[error("invalid public key: {0}")]
InvalidPublicKey(String),
#[error("invalid secret key: {0}")]
InvalidSecretKey(String),
#[error("invalid signature: {0}")]
InvalidSignature(String),
#[error("base64 decode error: {0}")]
Base64Decode(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("algorithm '{name}' not available; enable feature '{feature}'")]
AlgorithmNotAvailable { name: String, feature: String },
#[error("hybrid verification failed: classical (Ed25519) signature invalid")]
HybridClassicalFailed,
#[error("hybrid verification failed: post-quantum (ML-DSA) signature invalid")]
HybridPqcFailed,
#[error("internal error: {0}")]
Internal(String),
#[error("context string too long: {len} bytes (max 255)")]
ContextTooLong { len: usize },
#[error("digest length for {hash} must be {expected} bytes, got {got}")]
InvalidDigestLength { hash: &'static str, expected: usize, got: usize },
#[error("pre-hash {hash} ({strength}-bit collision strength) is too weak for {algorithm} (requires >= {required} bits)")]
PreHashTooWeak { hash: &'static str, strength: u32, algorithm: &'static str, required: u32 },
}
impl SigError {
pub fn to_wasm_string(&self) -> String {
self.to_string()
}
}
pub type SigResult<T> = Result<T, SigError>;