From 31bf2bc2b19850da0ef12c63da04f1adf074e292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 15 Feb 2018 00:53:11 +0100 Subject: [PATCH] Solved some warnings --- src/api/core/accounts.rs | 8 +++----- src/api/core/ciphers.rs | 9 ++++----- src/api/core/folders.rs | 8 +++----- src/api/core/mod.rs | 6 ++---- src/api/core/two_factor.rs | 2 -- src/api/icons.rs | 7 +++---- src/api/identity.rs | 10 +++++----- src/api/web.rs | 6 ++---- src/auth.rs | 9 +++------ src/db/models/attachment.rs | 3 --- src/db/models/cipher.rs | 3 +-- src/db/models/device.rs | 6 +----- src/db/models/folder.rs | 3 +-- src/db/models/user.rs | 5 ++--- src/main.rs | 3 +-- 15 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 7b3f7d61..66797f28 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -1,11 +1,9 @@ -use rocket::Route; use rocket::response::status::BadRequest; use rocket_contrib::{Json, Value}; use db::DbConn; use db::models::*; -use util; use auth::Headers; @@ -64,7 +62,7 @@ fn register(data: Json, conn: DbConn) -> Result<(), BadRequest Result> { +fn profile(headers: Headers) -> Result> { Ok(Json(headers.user.to_json())) } @@ -140,7 +138,7 @@ fn post_email(data: Json, headers: Headers, conn: DbConn) -> Result<(), B fn delete_account(data: Json, headers: Headers, conn: DbConn) -> Result<(), BadRequest> { let password_hash = data["masterPasswordHash"].as_str().unwrap(); - let mut user = headers.user; + let user = headers.user; if !user.check_valid_password(password_hash) { err!("Invalid password") @@ -154,7 +152,7 @@ fn delete_account(data: Json, headers: Headers, conn: DbConn) -> Result<( } #[get("/accounts/revision-date")] -fn revision_date(headers: Headers, conn: DbConn) -> Result> { +fn revision_date(headers: Headers) -> Result> { let revision_date = headers.user.updated_at.timestamp(); Ok(revision_date.to_string()) } diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 881c7b15..13afc65d 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -1,7 +1,6 @@ -use std::io::{Cursor, Read}; use std::path::Path; -use rocket::{Route, Data}; +use rocket::Data; use rocket::http::ContentType; use rocket::response::status::BadRequest; @@ -221,7 +220,7 @@ fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers .memory_threshold(0) .size_limit(None) .with_path(path) { - SaveResult::Full(SavedData::File(path, size)) => size as i32, + SaveResult::Full(SavedData::File(_, size)) => size as i32, _ => return }; @@ -233,8 +232,8 @@ fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers Ok(Json(cipher.to_json(&conn))) } -#[post("/ciphers//attachment//delete", data = "")] -fn delete_attachment_post(uuid: String, attachment_id: String, data: Json, headers: Headers, conn: DbConn) -> Result<(), BadRequest> { +#[post("/ciphers//attachment//delete", data = "<_data>")] +fn delete_attachment_post(uuid: String, attachment_id: String, _data: Json, headers: Headers, conn: DbConn) -> Result<(), BadRequest> { // Data contains a json object with the id, but we don't need it delete_attachment(uuid, attachment_id, headers, conn) } diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs index 23054aa8..fdf717c2 100644 --- a/src/api/core/folders.rs +++ b/src/api/core/folders.rs @@ -1,11 +1,9 @@ -use rocket::Route; use rocket::response::status::BadRequest; use rocket_contrib::{Json, Value}; use db::DbConn; use db::models::*; -use util; use auth::Headers; @@ -23,7 +21,7 @@ fn get_folders(headers: Headers, conn: DbConn) -> Result> #[get("/folders/")] fn get_folder(uuid: String, headers: Headers, conn: DbConn) -> Result> { - let mut folder = match Folder::find_by_uuid(&uuid, &conn) { + let folder = match Folder::find_by_uuid(&uuid, &conn) { Some(folder) => folder, _ => err!("Invalid folder") }; @@ -79,8 +77,8 @@ fn put_folder(uuid: String, data: Json, headers: Headers, conn: DbConn) - Ok(Json(folder.to_json())) } -#[post("/folders//delete", data = "")] -fn delete_folder_post(uuid: String, data: Json, headers: Headers, conn: DbConn) -> Result<(), BadRequest> { +#[post("/folders//delete", data = "<_data>")] +fn delete_folder_post(uuid: String, _data: Json, headers: Headers, conn: DbConn) -> Result<(), BadRequest> { // Data contains a json object with the id, but we don't need it delete_folder(uuid, headers, conn) } diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index b0609dd0..2e69a891 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -64,11 +64,9 @@ pub fn routes() -> Vec { use rocket::Route; use rocket::response::status::BadRequest; -use rocket_contrib::{Json, Value}; +use rocket_contrib::Json; use db::DbConn; -use db::models::*; -use util; use auth::Headers; @@ -107,7 +105,7 @@ fn post_eq_domains(data: Json, headers: Headers, conn: DbConn) let excluded_globals = &data.ExcludedGlobalEquivalentDomains; let equivalent_domains = &data.EquivalentDomains; - let mut user = headers.user; + let user = headers.user; //BODY. "{\"ExcludedGlobalEquivalentDomains\":[2],\"EquivalentDomains\":[[\"uoc.edu\",\"uoc.es\"]]}" diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index 641d2c77..54f7e240 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -1,4 +1,3 @@ -use rocket::Route; use rocket::response::status::BadRequest; use rocket_contrib::{Json, Value}; @@ -6,7 +5,6 @@ use rocket_contrib::{Json, Value}; use data_encoding::BASE32; use db::DbConn; -use db::models::*; use util; use crypto; diff --git a/src/api/icons.rs b/src/api/icons.rs index cd408512..0a8016b5 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -1,7 +1,6 @@ use std::io; use std::io::prelude::*; use std::fs::{create_dir_all, File}; -use std::path::Path; use rocket::Route; use rocket::response::Content; @@ -27,7 +26,7 @@ fn icon(domain: String) -> Content> { // Get the icon, or fallback in case of error let icon = match get_icon_cached(&domain, &url) { Ok(icon) => icon, - Err(e) => return Content(ContentType::PNG, get_fallback_icon()) + Err(_) => return Content(ContentType::PNG, get_fallback_icon()) }; Content(ContentType::PNG, icon) @@ -51,7 +50,7 @@ fn get_icon_cached(key: &str, url: &str) -> io::Result> { create_dir_all(&CONFIG.icon_cache_folder)?; let path = &format!("{}/{}.png", CONFIG.icon_cache_folder, key); - /// Try to read the cached icon, and return it if it exists + // Try to read the cached icon, and return it if it exists match File::open(path) { Ok(mut f) => { let mut buffer = Vec::new(); @@ -70,7 +69,7 @@ fn get_icon_cached(key: &str, url: &str) -> io::Result> { Err(_) => return Err(io::Error::new(io::ErrorKind::NotFound, "")) }; - /// Save the currently downloaded icon + // Save the currently downloaded icon match File::create(path) { Ok(mut f) => { f.write_all(&icon); } Err(_) => { /* Continue */ } diff --git a/src/api/identity.rs b/src/api/identity.rs index ce11f888..e1623fae 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -71,12 +71,12 @@ fn login(connect_data: Form, conn: DbConn) -> Result FromForm<'f> for ConnectData { type Error = String; - fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result { + fn from_form(items: &mut FormItems<'f>, _strict: bool) -> Result { let mut data = HashMap::new(); // Insert data into map for (key, value) in items { let decoded_key: String = match key.url_decode() { Ok(decoded) => decoded, - Err(e) => return Err(format!("Error decoding key: {}", value)), + Err(_) => return Err(format!("Error decoding key: {}", value)), }; let decoded_value: String = match value.url_decode() { Ok(decoded) => decoded, - Err(e) => return Err(format!("Error decoding value: {}", value)), + Err(_) => return Err(format!("Error decoding value: {}", value)), }; data.insert(decoded_key.to_lowercase(), decoded_value); diff --git a/src/api/web.rs b/src/api/web.rs index f2007747..8e39b3a9 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -3,9 +3,7 @@ use std::path::{Path, PathBuf}; use rocket::Route; use rocket::response::NamedFile; -use rocket_contrib::{Json, Value}; - -use auth::Headers; +use rocket_contrib::Json; use CONFIG; @@ -42,7 +40,7 @@ fn attachments(uuid: String, file: PathBuf) -> io::Result { #[get("/alive")] fn alive() -> Json { use util::format_date; - use chrono::{NaiveDateTime, Utc}; + use chrono::Utc; Json(format_date(&Utc::now().naive_utc())) } diff --git a/src/auth.rs b/src/auth.rs index 5a8172cc..5ef66725 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -3,12 +3,10 @@ /// use util::read_file; -use std::path::Path; use time::Duration; use jwt; use serde::ser::Serialize; -use serde::de::Deserialize; use CONFIG; @@ -89,7 +87,6 @@ pub struct JWTClaims { /// use rocket::Outcome; -use rocket::http::Status; use rocket::request::{self, Request, FromRequest}; use db::DbConn; @@ -107,14 +104,14 @@ impl<'a, 'r> FromRequest<'a, 'r> for Headers { fn from_request(request: &'a Request<'r>) -> request::Outcome { let headers = request.headers(); - /// Get device type + // Get device type let device_type = match headers.get_one("Device-Type") .map(|s| s.parse::()) { Some(Ok(dt)) => Some(dt),// dt, _ => None // return err_handler!("Device-Type is invalid or missing") }; - /// Get access_token + // Get access_token let access_token: &str = match request.headers().get_one("Authorization") { Some(a) => { let split: Option<&str> = a.rsplit("Bearer ").next(); @@ -128,7 +125,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Headers { None => err_handler!("No access token provided") }; - /// Check JWT token is valid and get device and user from it + // Check JWT token is valid and get device and user from it let claims: JWTClaims = match decode_jwt(access_token) { Ok(claims) => claims, Err(msg) => { diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index 2591d80a..0174acb3 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -31,14 +31,11 @@ impl Attachment { pub fn to_json(&self) -> JsonValue { use util::get_display_size; - use CONFIG; // TODO: Change all references to localhost (maybe put it in .env?) let host = "http://localhost:8000"; let web_path = format!("{}/attachments/{}/{}", host, self.cipher_uuid, self.id); - - let file_path = self.get_file_path(); let display_size = get_display_size(self.file_size); json!({ diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 0fcb24f4..20b7b861 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -1,5 +1,4 @@ -use chrono::{NaiveDate, NaiveDateTime, Utc}; -use time::Duration; +use chrono::{NaiveDateTime, Utc}; use serde_json::Value as JsonValue; use uuid::Uuid; diff --git a/src/db/models/device.rs b/src/db/models/device.rs index 6bb4d7ab..a22f45fd 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -1,8 +1,4 @@ -use chrono::{NaiveDate, NaiveDateTime, Utc}; -use time::Duration; -use serde_json::Value as JsonValue; - -use uuid::Uuid; +use chrono::{NaiveDateTime, Utc}; use super::User; diff --git a/src/db/models/folder.rs b/src/db/models/folder.rs index da4d0bbd..18561768 100644 --- a/src/db/models/folder.rs +++ b/src/db/models/folder.rs @@ -1,5 +1,4 @@ -use chrono::{NaiveDate, NaiveDateTime, Utc}; -use time::Duration; +use chrono::{NaiveDateTime, Utc}; use serde_json::Value as JsonValue; use uuid::Uuid; diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 77e0f420..ce6807a3 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -1,5 +1,4 @@ -use chrono::{NaiveDate, NaiveDateTime, Utc}; -use time::Duration; +use chrono::{NaiveDateTime, Utc}; use serde_json::Value as JsonValue; use uuid::Uuid; @@ -100,7 +99,7 @@ impl User { let decoded_secret = match BASE32.decode(totp_secret.as_bytes()) { Ok(s) => s, - Err(e) => return false + Err(_) => return false }; let generated = totp_raw_now(&decoded_secret, 6, 0, 30, &HashType::SHA1); diff --git a/src/main.rs b/src/main.rs index acfafe27..bdb2f1a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,9 @@ -#![allow(dead_code, unused_variables, unused, unused_mut)] +#![allow(unused)] #![feature(plugin, custom_derive)] #![cfg_attr(test, plugin(stainless))] #![plugin(rocket_codegen)] extern crate rocket; -#[macro_use] extern crate rocket_contrib; extern crate reqwest; extern crate multipart;