Skip to main content

ruma_common/identifiers/
acr.rs

1//! Authentication Context Class Reference.
2
3use ruma_macros::IdDst;
4
5/// An Authentication Context Class Reference, as defined in the
6/// [OpenID Connect specification].
7///
8/// ACRs are opaque, non-empty tokens containing no whitespace.
9///
10/// [OpenID Connect specification]: https://openid.net/specs/openid-connect-core-1_0.html#IDToken:~:text=string%2E-,acr
11#[repr(transparent)]
12#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, IdDst)]
13#[ruma_id(validate = ruma_identifiers_validation::acr::validate)]
14pub struct Acr(str);
15
16#[cfg(test)]
17mod tests {
18    use ruma_identifiers_validation::Error;
19
20    use super::Acr;
21
22    #[test]
23    fn validate_acr() {
24        Acr::parse("urn:example:cve").unwrap();
25        Acr::parse("🛡️").unwrap();
26
27        assert_eq!(Acr::parse("etaoin shrdlu"), Err(Error::InvalidCharacters));
28        assert_eq!(Acr::parse(""), Err(Error::Empty));
29    }
30}