ruma_identifiers_validation/acr.rs
1use crate::Error;
2
3/// Validate the format of an Authentication Context Class Reference, as defined
4/// in the [OpenID Connect specification].
5///
6/// The specification does not define an allowable character set for ACR values.
7/// Because the `acr_values` query parameter accepts them as a space-separated
8/// list, this function validates that the ACR is not empty and contains no whitespace.
9///
10/// [OpenID Connect specification]: https://openid.net/specs/openid-connect-core-1_0.html#IDToken:~:text=string%2E-,acr
11pub fn validate(acr: &str) -> Result<(), Error> {
12 if acr.is_empty() {
13 return Err(Error::Empty);
14 }
15
16 if acr.chars().any(|char| char.is_ascii_whitespace()) {
17 return Err(Error::InvalidCharacters);
18 }
19
20 Ok(())
21}