Skip to content

Commit

Permalink
Address trivial clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
callahad committed Oct 26, 2016
1 parent e99dba5 commit 3d89588
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
@@ -1 +1 @@
doc-valid-idents = ["OpenID", "OAuth", "POSTed"]
doc-valid-idents = ["OpenID", "OAuth", "OAuth2", "POSTed"]
13 changes: 7 additions & 6 deletions src/config.rs
Expand Up @@ -43,7 +43,7 @@ impl Template {
pub fn render(&self, params: &[(&str, &str)]) -> String {
let mut builder = mustache::MapBuilder::new();
for &param in params {
let (ref key, ref value) = param;
let (key, value) = param;
builder = builder.insert_str(key, value);
}
self.render_data(&builder.build())
Expand Down Expand Up @@ -116,6 +116,7 @@ pub struct Config {
}


#[derive(Clone, Debug, Default)]
pub struct ConfigBuilder {
pub listen_ip: String,
pub listen_port: u16,
Expand All @@ -135,7 +136,7 @@ pub struct ConfigBuilder {
}


#[derive(Clone)]
#[derive(Clone, Debug, Default)]
pub struct ProviderBuilder {
pub client_id: Option<String>,
pub secret: Option<String>,
Expand Down Expand Up @@ -200,7 +201,7 @@ impl ConfigBuilder {
}
}

pub fn update_from_file(&mut self, path: &String) -> Result<&mut ConfigBuilder, ConfigError> {
pub fn update_from_file(&mut self, path: &str) -> Result<&mut ConfigBuilder, ConfigError> {
let mut file = try!(File::open(path));
let mut file_contents = String::new();
try!(file.read_to_string(&mut file_contents));
Expand Down Expand Up @@ -265,7 +266,7 @@ impl ConfigBuilder {
self.public_url = Some(format!("https://{}.herokuapp.com", val));
}

for var in ["REDISTOGO_URL", "REDISGREEN_URL", "REDISCLOUD_URL", "REDIS_URL", "OPENREDIS_URL"].iter() {
for var in &["REDISTOGO_URL", "REDISGREEN_URL", "REDISCLOUD_URL", "REDIS_URL", "OPENREDIS_URL"] {
if let Ok(val) = env::var(var) {
self.redis_url = Some(val);
break;
Expand Down Expand Up @@ -299,7 +300,7 @@ impl ConfigBuilder {
// New scope to avoid mutably borrowing `self` twice
{
let mut gmail_provider = self.providers.entry("gmail.com".to_string())
.or_insert_with(|| ProviderBuilder::new_gmail());
.or_insert_with(ProviderBuilder::new_gmail);

if let Some(val) = env_config.broker_gmail_secret { gmail_provider.secret = Some(val); }
if let Some(val) = env_config.broker_gmail_client { gmail_provider.client_id = Some(val); }
Expand All @@ -320,7 +321,7 @@ impl ConfigBuilder {

// Child structs
let keys = self.keyfiles.iter().filter_map(|path| {
crypto::NamedKey::from_file(&path).ok()
crypto::NamedKey::from_file(path).ok()
}).collect();

let store = store::Store::new(
Expand Down
2 changes: 1 addition & 1 deletion src/crypto.rs
Expand Up @@ -165,7 +165,7 @@ pub fn verify_jws(jws: &str, key_set: &Value) -> Result<Value, ()> {

// Verify the identity token's signature.
let message_len = parts[0].len() + parts[1].len() + 1;
let sha256 = hash::hash(hash::Type::SHA256, &jws[..message_len].as_bytes());
let sha256 = hash::hash(hash::Type::SHA256, jws[..message_len].as_bytes());
if !pub_key.verify(&sha256, &decoded[2]) {
return Err(());
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Expand Up @@ -43,7 +43,7 @@ pub mod store_cache;
use error::{BrokerResult, BrokerError};


/// Iron extension key we use to store the redirect_uri.
/// Iron extension key we use to store the `redirect_uri`.
/// Once set, the error handler will return errors to the RP.
struct RedirectUri;
impl typemap::Key for RedirectUri { type Value = Url; }
Expand Down Expand Up @@ -75,7 +75,7 @@ macro_rules! broker_handler {

/// Macro used to extract a parameter from a QueryMap.
///
/// Will return from the caller with a BrokerError if
/// Will return from the caller with a `BrokerError` if
/// the parameter is missing and has no default.
///
/// ```
Expand Down Expand Up @@ -121,7 +121,7 @@ fn return_to_relier(app: &Config, redirect_uri: &str, params: &[(&str, &str)])
}


/// Handle an BrokerError and create an IronResult.
/// Handle an `BrokerError` and create an `IronResult`.
///
/// The `broker_handler!` macro calls this on error. We don't use a `From`
/// implementation, because this way we get app and request context, and we
Expand Down Expand Up @@ -171,12 +171,12 @@ fn handle_error(app: &Config, req: &mut Request, err: BrokerError) -> IronResult
("error", &description),
]))))
},
(err @ _, Some(redirect_uri)) => {
(err, Some(redirect_uri)) => {
Err(IronError::new(err, return_to_relier(app, &redirect_uri, &[
("error", "server_error"),
])))
},
(err @ _, None) => {
(err, None) => {
Err(IronError::new(err, (status::InternalServerError,
modifiers::Header(ContentType::html()),
app.templates.error.render(&[
Expand Down Expand Up @@ -347,7 +347,7 @@ fn create_jwt(app: &Config, email: &str, origin: &str, nonce: &str) -> String {
.insert("sub", email)
.insert("nonce", nonce)
.build();
app.keys.last().unwrap().sign_jws(&payload)
app.keys.last().unwrap().sign_jws(payload)
}


Expand Down
6 changes: 3 additions & 3 deletions src/oidc.rs
Expand Up @@ -100,13 +100,13 @@ pub fn request(app: &Config, email_addr: EmailAddress, client_id: &str, nonce: &
}

pub fn canonicalize_google(email: String) -> String {
let at = email.find("@").unwrap();
let at = email.find('@').unwrap();
let (user, domain) = email.split_at(at);
let domain = &domain[1..];
let user = &user.replace(".", ""); // Ignore dots

// Trim plus addresses
let user = match user.find("+") {
let user = match user.find('+') {
Some(pos) => user.split_at(pos).0,
None => user,
};
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn verify(app: &Config, stored: &HashMap<String, String>, code: &str)
headers.set(HyContentType::form_url_encoded());
try!(
client.post(token_url).headers(headers).body(&body).send()
.map_err(|e| BrokerError::Http(e))
.map_err(BrokerError::Http)
.and_then(|rsp| from_reader(rsp).map_err(|_| {
BrokerError::Provider("failed to parse response as JSON".to_string())
}))
Expand Down

0 comments on commit 3d89588

Please sign in to comment.