From baa8d566532776366af6dffbdf2427f8c2941639 Mon Sep 17 00:00:00 2001 From: Glenn Griffin Date: Fri, 15 Nov 2019 09:57:28 -0800 Subject: [PATCH] JSONToken should always contain scopes. This is already the case when writing a token file. Presumably the only reason it was an Option was for backwards compatibility, but we're already breaking compatibility with the change to the hash value so this seems like an appropriate time to make the change. This change also highlights how unused the hash value has been previously. Future changes plan to use the hash value for more efficient handling. --- src/storage.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index 5481700..c8a2696 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -94,7 +94,7 @@ impl Storage { #[derive(Debug, Clone, Serialize, Deserialize)] struct JSONToken { pub hash: u64, - pub scopes: Option>, + pub scopes: Vec, pub token: Token, } @@ -141,15 +141,11 @@ impl JSONTokens { T: AsRef, { for t in self.tokens.iter() { - if let Some(token_scopes) = &t.scopes { - if scopes - .scopes - .iter() - .all(|s| token_scopes.iter().any(|t| t == s.as_ref())) - { - return Some(t.token.clone()); - } - } else if scopes.hash == t.hash { + if scopes + .scopes + .iter() + .all(|s| t.scopes.iter().any(|t| t == s.as_ref())) + { return Some(t.token.clone()); } } @@ -165,13 +161,11 @@ impl JSONTokens { self.tokens.push(JSONToken { hash: scopes.hash, - scopes: Some( - scopes - .scopes - .iter() - .map(|x| x.as_ref().to_string()) - .collect(), - ), + scopes: scopes + .scopes + .iter() + .map(|x| x.as_ref().to_string()) + .collect(), token, }); }