Skip to main content

flp_saml2/
error.rs

1// This library provides SAML2 implementation in Rust
2// Copyright (C) 2026  Hakukaze Shikano
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17use openssl::error::ErrorStack;
18use quick_xml::DeError;
19use std::{fmt, io};
20
21#[derive(Debug)]
22pub enum Error {
23    IOError(String),
24    InvalidCert(String),
25    InvalidResponse(String),
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match &self {
31            Self::IOError(s) => write!(f, "IO Error: {}", s),
32            Self::InvalidCert(s) => write!(f, "Invalid Cert: {}", s),
33            Self::InvalidResponse(s) => write!(f, "Invalid Response: {}", s),
34        }
35    }
36}
37
38impl std::error::Error for Error {}
39
40impl From<io::Error> for Error {
41    fn from(err: io::Error) -> Self {
42        Self::IOError(err.to_string())
43    }
44}
45
46impl From<ErrorStack> for Error {
47    fn from(err: ErrorStack) -> Self {
48        Self::InvalidCert(err.to_string())
49    }
50}
51
52impl From<DeError> for Error {
53    fn from(err: DeError) -> Self {
54        Self::InvalidResponse(err.to_string())
55    }
56}
57
58pub type Result<T> = std::result::Result<T, Error>;