use super::SessionError;
use ic_auth_protocol_types::ScopeLabel;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RequiredScopes(Vec<ScopeLabel>);
impl RequiredScopes {
pub const NONE: &'static Self = &Self(Vec::new());
pub fn new(scopes: Vec<String>) -> Result<Self, SessionError> {
if scopes.len() > crate::limits::MAX_SESSION_SCOPES {
return Err(SessionError::InvalidPolicyOrRecord);
}
let scopes =
ScopeLabel::from_strings(scopes).map_err(crate::canonical::CanonicalAuthError::from)?;
Ok(Self(scopes))
}
pub fn as_slice(&self) -> &[ScopeLabel] {
&self.0
}
}