use crate::error::{MechanismError, MechanismErrorKind};
use crate::property::SizedProperty;
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum Error {
#[error("failed to parse message")]
Parse(
#[source]
#[from]
super::parser::ParseError,
),
#[error("failed to serialize error message")]
Serde(
#[source]
#[from]
serde_json::Error,
),
}
impl MechanismError for Error {
fn kind(&self) -> MechanismErrorKind {
MechanismErrorKind::Parse
}
}
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct OAuthBearerError<'a> {
pub status: &'a str,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scope: Option<&'a str>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "openid-configuration"
)]
pub openid_config: Option<&'a str>,
}
impl<'a> OAuthBearerError<'a> {
#[must_use]
pub const fn new(
status: &'a str,
scope: Option<&'a str>,
openid_config: Option<&'a str>,
) -> Self {
Self {
status,
scope,
openid_config,
}
}
}
#[non_exhaustive]
pub struct OAuthBearerValidate;
impl<'a> SizedProperty<'a> for OAuthBearerValidate {
type Value = Result<(), OAuthBearerError<'a>>;
}
#[non_exhaustive]
pub struct OAuthBearerErrored;
impl<'a> SizedProperty<'a> for OAuthBearerErrored {
type Value = OAuthBearerError<'a>;
}