Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved scope struct access #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions oxide-auth/src/primitives/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::{cmp, fmt, str};

use std::collections::HashSet;
use std::convert::TryFrom;
use serde::{Deserialize, Serialize};

/// Scope of a given grant or resource, a set of scope-tokens separated by spaces.
Expand Down Expand Up @@ -95,6 +96,24 @@ impl Scope {
pub fn iter(&self) -> impl Iterator<Item = &str> {
self.tokens.iter().map(AsRef::as_ref)
}

/// Convert self to an iterator over the individual scopes.
pub fn into_iter(self) -> impl Iterator<Item = String> {
self.tokens.into_iter()
}
}

impl TryFrom<HashSet<String>> for Scope {
type Error = ParseScopeErr;

fn try_from(tokens: HashSet<String>) -> Result<Self, Self::Error> {
for token in &tokens {
if let Some(char) = token.chars().find(|it|Self::invalid_scope_char(*it) || it == &' ') {
return Err(ParseScopeErr::InvalidCharacter(char));
}
}
Ok(Self {tokens})
}
}

/// Error returned from parsing a scope as encoded in an authorization token request.
Expand Down