saml_rs/model/
endpoint.rs1use crate::error::SamlError;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct EndpointUrl(String);
6
7impl EndpointUrl {
8 pub fn try_new(value: impl Into<String>) -> Result<Self, SamlError> {
14 let value = value.into();
15 let parsed = url::Url::parse(&value).map_err(|err| SamlError::Invalid(err.to_string()))?;
16 if matches!(parsed.scheme(), "http" | "https") && parsed.has_host() {
17 return Ok(Self(value));
18 }
19 Err(SamlError::Invalid(
20 "endpoint URL must be absolute HTTP(S)".into(),
21 ))
22 }
23
24 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28}