use crate::config::NameIdFormat;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NameId {
value: String,
format: Option<NameIdFormat>,
}
impl NameId {
pub fn new(value: impl Into<String>, format: Option<NameIdFormat>) -> Self {
Self {
value: value.into(),
format,
}
}
pub fn value(&self) -> &str {
&self.value
}
pub fn format(&self) -> Option<&NameIdFormat> {
self.format.as_ref()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NameIdPolicy {
format: Option<NameIdFormat>,
creation_request: NameIdCreationRequest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NameIdCreationRequest {
Unspecified,
AllowCreate,
DoNotAllowCreate,
}
impl NameIdPolicy {
pub fn new(format: Option<NameIdFormat>, creation_request: NameIdCreationRequest) -> Self {
Self {
format,
creation_request,
}
}
pub fn unspecified(format: Option<NameIdFormat>) -> Self {
Self::new(format, NameIdCreationRequest::Unspecified)
}
pub fn allow_creation(format: Option<NameIdFormat>) -> Self {
Self::new(format, NameIdCreationRequest::AllowCreate)
}
pub fn disallow_creation(format: Option<NameIdFormat>) -> Self {
Self::new(format, NameIdCreationRequest::DoNotAllowCreate)
}
pub(crate) fn from_parsed(
format: Option<NameIdFormat>,
allow_create: Option<bool>,
) -> Option<Self> {
if format.is_none() && allow_create.is_none() {
return None;
}
Some(match allow_create {
Some(true) => Self::allow_creation(format),
Some(false) => Self::disallow_creation(format),
None => Self::unspecified(format),
})
}
pub fn format(&self) -> Option<&NameIdFormat> {
self.format.as_ref()
}
pub fn creation_request(&self) -> NameIdCreationRequest {
self.creation_request
}
pub fn allow_create(&self) -> Option<bool> {
match self.creation_request {
NameIdCreationRequest::Unspecified => None,
NameIdCreationRequest::AllowCreate => Some(true),
NameIdCreationRequest::DoNotAllowCreate => Some(false),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SubjectConfirmation {
raw_xml: String,
}
impl SubjectConfirmation {
pub fn from_raw_xml(raw_xml: impl Into<String>) -> Self {
Self {
raw_xml: raw_xml.into(),
}
}
pub fn raw_xml(&self) -> &str {
&self.raw_xml
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Subject {
name_id: NameId,
confirmations: Vec<SubjectConfirmation>,
}
impl Subject {
pub fn new(name_id: NameId, confirmations: Vec<SubjectConfirmation>) -> Self {
Self {
name_id,
confirmations,
}
}
pub fn name_id(&self) -> &NameId {
&self.name_id
}
pub fn confirmations(&self) -> &[SubjectConfirmation] {
&self.confirmations
}
}