use crate::config::NameIdFormat;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NameId {
value: String,
format: Option<NameIdFormat>,
name_qualifier: Option<String>,
sp_name_qualifier: Option<String>,
sp_provided_id: Option<String>,
}
impl NameId {
pub fn new(value: impl Into<String>, format: Option<NameIdFormat>) -> Self {
Self::with_qualifiers(value, format, None, None, None)
}
pub fn with_qualifiers(
value: impl Into<String>,
format: Option<NameIdFormat>,
name_qualifier: Option<String>,
sp_name_qualifier: Option<String>,
sp_provided_id: Option<String>,
) -> Self {
Self {
value: value.into(),
format,
name_qualifier,
sp_name_qualifier,
sp_provided_id,
}
}
pub fn value(&self) -> &str {
&self.value
}
pub fn format(&self) -> Option<&NameIdFormat> {
self.format.as_ref()
}
pub fn name_qualifier(&self) -> Option<&str> {
self.name_qualifier.as_deref()
}
pub fn sp_name_qualifier(&self) -> Option<&str> {
self.sp_name_qualifier.as_deref()
}
pub fn sp_provided_id(&self) -> Option<&str> {
self.sp_provided_id.as_deref()
}
}
#[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
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequestedSubject {
identifier: RequestedSubjectIdentifier,
confirmations: Vec<SubjectConfirmation>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RequestedSubjectIdentifier {
NoIdentifier,
NameId(NameId),
BaseId,
EncryptedId,
}
impl RequestedSubject {
pub(crate) fn new(
identifier: RequestedSubjectIdentifier,
confirmations: Vec<SubjectConfirmation>,
) -> Self {
Self {
identifier,
confirmations,
}
}
pub fn identifier(&self) -> &RequestedSubjectIdentifier {
&self.identifier
}
pub fn name_id(&self) -> Option<&NameId> {
match &self.identifier {
RequestedSubjectIdentifier::NameId(name_id) => Some(name_id),
RequestedSubjectIdentifier::NoIdentifier
| RequestedSubjectIdentifier::BaseId
| RequestedSubjectIdentifier::EncryptedId => None,
}
}
pub fn confirmations(&self) -> &[SubjectConfirmation] {
&self.confirmations
}
}