commit 31bf2bc2b19850da0ef12c63da04f1adf074e292
parent b54684b677fd399011fa7061dc7c0926f3d17c4b
Author: Daniel GarcĂa <dani-garcia@users.noreply.github.com>
Date: Thu, 15 Feb 2018 00:53:11 +0100
Solved some warnings
Diffstat:
15 files changed, 31 insertions(+), 57 deletions(-)
diff --git 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<RegisterData>, conn: DbConn) -> Result<(), BadRequest<Jso
}
#[get("/accounts/profile")]
-fn profile(headers: Headers, conn: DbConn) -> Result<Json, BadRequest<Json>> {
+fn profile(headers: Headers) -> Result<Json, BadRequest<Json>> {
Ok(Json(headers.user.to_json()))
}
@@ -140,7 +138,7 @@ fn post_email(data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), B
fn delete_account(data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
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<Value>, headers: Headers, conn: DbConn) -> Result<(
}
#[get("/accounts/revision-date")]
-fn revision_date(headers: Headers, conn: DbConn) -> Result<String, BadRequest<Json>> {
+fn revision_date(headers: Headers) -> Result<String, BadRequest<Json>> {
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
@@ -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/<uuid>/attachment/<attachment_id>/delete", data = "<data>")]
-fn delete_attachment_post(uuid: String, attachment_id: String, data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
+#[post("/ciphers/<uuid>/attachment/<attachment_id>/delete", data = "<_data>")]
+fn delete_attachment_post(uuid: String, attachment_id: String, _data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
// 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
@@ -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<Json, BadRequest<Json>>
#[get("/folders/<uuid>")]
fn get_folder(uuid: String, headers: Headers, conn: DbConn) -> Result<Json, BadRequest<Json>> {
- 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<Value>, headers: Headers, conn: DbConn) -
Ok(Json(folder.to_json()))
}
-#[post("/folders/<uuid>/delete", data = "<data>")]
-fn delete_folder_post(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
+#[post("/folders/<uuid>/delete", data = "<_data>")]
+fn delete_folder_post(uuid: String, _data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
// 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
@@ -64,11 +64,9 @@ pub fn routes() -> Vec<Route> {
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<EquivDomainData>, 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
@@ -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
@@ -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<Vec<u8>> {
// 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<Vec<u8>> {
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<Vec<u8>> {
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
@@ -71,12 +71,12 @@ fn login(connect_data: Form<ConnectData>, conn: DbConn) -> Result<Json, BadReque
if !user.check_totp_code(totp_code) {
// Return error 400
- return err_json!(json!({
+ err_json!(json!({
"error" : "invalid_grant",
"error_description" : "Two factor required.",
"TwoFactorProviders" : [ 0 ],
"TwoFactorProviders2" : { "0" : null }
- }));
+ }))
}
// Let's only use the header and ignore the 'devicetype' parameter
@@ -159,19 +159,19 @@ const VALUES_DEVICE: [&str; 3] = ["deviceidentifier",
impl<'f> FromForm<'f> for ConnectData {
type Error = String;
- fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, Self::Error> {
+ fn from_form(items: &mut FormItems<'f>, _strict: bool) -> Result<Self, Self::Error> {
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
@@ -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<NamedFile> {
#[get("/alive")]
fn alive() -> Json<String> {
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
@@ -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<Self, Self::Error> {
let headers = request.headers();
- /// Get device type
+ // Get device type
let device_type = match headers.get_one("Device-Type")
.map(|s| s.parse::<i32>()) {
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;