Skip to content

Commit

Permalink
fix(TokenStorage): set() returns Result<(), _>
Browse files Browse the repository at this point in the history
That we, we are conforming to the style postulated by the standard
library, which, if in doubt, should always be preferred.

Fixes #5
  • Loading branch information
Byron committed Apr 30, 2015
1 parent e05e555 commit f95bb81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "yup-oauth2"
version = "0.4.0"
version = "0.4.1"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
16 changes: 8 additions & 8 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait TokenStorage {

/// If `token` is None, it is invalid or revoked and should be removed from storage.
/// Otherwise, it should be saved.
fn set(&mut self, scope_hash: u64, scopes: &Vec<&str>, token: Option<Token>) -> Option<Self::Error>;
fn set(&mut self, scope_hash: u64, scopes: &Vec<&str>, token: Option<Token>) -> Result<(), Self::Error>;
/// A `None` result indicates that there is no token for the given scope_hash.
fn get(&self, scope_hash: u64, scopes: &Vec<&str>) -> Result<Option<Token>, Self::Error>;
}
Expand All @@ -50,7 +50,7 @@ impl fmt::Display for NullError {

impl TokenStorage for NullStorage {
type Error = NullError;
fn set(&mut self, _: u64, _: &Vec<&str>, _: Option<Token>) -> Option<NullError> { None }
fn set(&mut self, _: u64, _: &Vec<&str>, _: Option<Token>) -> Result<(), NullError> { Ok(()) }
fn get(&self, _: u64, _: &Vec<&str>) -> Result<Option<Token>, NullError> { Ok(None) }
}

Expand All @@ -63,12 +63,12 @@ pub struct MemoryStorage {
impl TokenStorage for MemoryStorage {
type Error = NullError;

fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<NullError> {
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Result<(), NullError> {
match token {
Some(t) => self.tokens.insert(scope_hash, t),
None => self.tokens.remove(&scope_hash),
};
None
Ok(())
}

fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, NullError> {
Expand Down Expand Up @@ -308,16 +308,16 @@ impl<D, S, C> GetToken for Authenticator<D, S, C>
self.delegate.token_refresh_failed(&err_str, &err_description);
let storage_err =
match self.storage.set(scope_key, &scopes, None) {
None => String::new(),
Some(err) => err.to_string(),
Ok(_) => String::new(),
Err(err) => err.to_string(),
};
return Err(Box::new(
StringError::new(storage_err + err_str, err_description.as_ref())))
},
RefreshResult::Success(ref new_t) => {
t = new_t.clone();
loop {
if let Some(err) = self.storage.set(scope_key, &scopes, Some(t.clone())) {
if let Err(err) = self.storage.set(scope_key, &scopes, Some(t.clone())) {
match self.delegate.token_storage_failure(true, &err) {
Retry::Skip => break,
Retry::Abort => return Err(Box::new(err)),
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<D, S, C> GetToken for Authenticator<D, S, C>
{
Ok(token) => {
loop {
if let Some(err) = self.storage.set(scope_key, &scopes, Some(token.clone())) {
if let Err(err) = self.storage.set(scope_key, &scopes, Some(token.clone())) {
match self.delegate.token_storage_failure(true, &err) {
Retry::Skip => break,
Retry::Abort => return Err(Box::new(err)),
Expand Down

0 comments on commit f95bb81

Please sign in to comment.