use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::types::{tid_issued_at, NumericDate};
#[derive(Serialize, Deserialize, Default, Clone, Copy, Debug, PartialEq, Eq)]
pub struct NoApp {}
#[derive(Debug)]
pub(crate) struct MandateFields<T> {
pub exp: Option<NumericDate>,
pub tid: Option<Uuid>,
pub iss: Option<String>,
pub aud: Option<Vec<String>>,
pub sub: Option<String>,
pub app: T,
}
#[derive(Debug)]
pub struct Clauses<T> {
pub(crate) inner: MandateFields<T>,
}
impl<T> Clauses<T> {
pub fn exp(&self) -> NumericDate {
self.inner.exp.expect("verified mandate has exp")
}
pub fn tid(&self) -> Uuid {
self.inner.tid.expect("verified mandate has tid")
}
pub fn issued_at(&self) -> NumericDate {
tid_issued_at(self.tid())
}
pub fn issuer(&self) -> Option<&str> {
self.inner.iss.as_deref()
}
pub fn iss(&self) -> Option<&str> {
self.issuer()
}
pub fn audience(&self) -> Option<&[String]> {
self.inner.aud.as_deref()
}
pub fn aud(&self) -> Option<&[String]> {
self.audience()
}
pub fn subject(&self) -> Option<&str> {
self.inner.sub.as_deref()
}
pub fn sub(&self) -> Option<&str> {
self.subject()
}
pub fn app(&self) -> &T {
&self.inner.app
}
pub fn into_app(self) -> T {
self.inner.app
}
}
#[derive(Debug)]
pub(crate) struct ManifestFields<T> {
pub iss: String,
pub exp: Option<NumericDate>,
pub app: T,
}
#[derive(Debug)]
pub struct Claims<T> {
pub(crate) inner: ManifestFields<T>,
}
impl<T> Claims<T> {
pub fn issuer(&self) -> &str {
&self.inner.iss
}
pub fn iss(&self) -> &str {
self.issuer()
}
pub fn exp(&self) -> Option<NumericDate> {
self.inner.exp
}
pub fn app(&self) -> &T {
&self.inner.app
}
pub fn into_app(self) -> T {
self.inner.app
}
}