1
0
Fork 0

Solved some warnings

Dieser Commit ist enthalten in:
Daniel García 2018-02-15 00:53:11 +01:00
Ursprung b54684b677
Commit 31bf2bc2b1
15 geänderte Dateien mit 31 neuen und 57 gelöschten Zeilen

Datei anzeigen

@ -1,11 +1,9 @@
use rocket::Route;
use rocket::response::status::BadRequest; use rocket::response::status::BadRequest;
use rocket_contrib::{Json, Value}; use rocket_contrib::{Json, Value};
use db::DbConn; use db::DbConn;
use db::models::*; use db::models::*;
use util;
use auth::Headers; use auth::Headers;
@ -64,7 +62,7 @@ fn register(data: Json<RegisterData>, conn: DbConn) -> Result<(), BadRequest<Jso
} }
#[get("/accounts/profile")] #[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())) 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>> { fn delete_account(data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> {
let password_hash = data["masterPasswordHash"].as_str().unwrap(); let password_hash = data["masterPasswordHash"].as_str().unwrap();
let mut user = headers.user; let user = headers.user;
if !user.check_valid_password(password_hash) { if !user.check_valid_password(password_hash) {
err!("Invalid password") err!("Invalid password")
@ -154,7 +152,7 @@ fn delete_account(data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(
} }
#[get("/accounts/revision-date")] #[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(); let revision_date = headers.user.updated_at.timestamp();
Ok(revision_date.to_string()) Ok(revision_date.to_string())
} }

Datei anzeigen

@ -1,7 +1,6 @@
use std::io::{Cursor, Read};
use std::path::Path; use std::path::Path;
use rocket::{Route, Data}; use rocket::Data;
use rocket::http::ContentType; use rocket::http::ContentType;
use rocket::response::status::BadRequest; use rocket::response::status::BadRequest;
@ -221,7 +220,7 @@ fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers
.memory_threshold(0) .memory_threshold(0)
.size_limit(None) .size_limit(None)
.with_path(path) { .with_path(path) {
SaveResult::Full(SavedData::File(path, size)) => size as i32, SaveResult::Full(SavedData::File(_, size)) => size as i32,
_ => return _ => return
}; };
@ -233,8 +232,8 @@ fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers
Ok(Json(cipher.to_json(&conn))) Ok(Json(cipher.to_json(&conn)))
} }
#[post("/ciphers/<uuid>/attachment/<attachment_id>/delete", data = "<data>")] #[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>> { 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 // Data contains a json object with the id, but we don't need it
delete_attachment(uuid, attachment_id, headers, conn) delete_attachment(uuid, attachment_id, headers, conn)
} }

Datei anzeigen

@ -1,11 +1,9 @@
use rocket::Route;
use rocket::response::status::BadRequest; use rocket::response::status::BadRequest;
use rocket_contrib::{Json, Value}; use rocket_contrib::{Json, Value};
use db::DbConn; use db::DbConn;
use db::models::*; use db::models::*;
use util;
use auth::Headers; use auth::Headers;
@ -23,7 +21,7 @@ fn get_folders(headers: Headers, conn: DbConn) -> Result<Json, BadRequest<Json>>
#[get("/folders/<uuid>")] #[get("/folders/<uuid>")]
fn get_folder(uuid: String, headers: Headers, conn: DbConn) -> Result<Json, BadRequest<Json>> { 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, Some(folder) => folder,
_ => err!("Invalid 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())) Ok(Json(folder.to_json()))
} }
#[post("/folders/<uuid>/delete", data = "<data>")] #[post("/folders/<uuid>/delete", data = "<_data>")]
fn delete_folder_post(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> Result<(), BadRequest<Json>> { 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 // Data contains a json object with the id, but we don't need it
delete_folder(uuid, headers, conn) delete_folder(uuid, headers, conn)
} }

Datei anzeigen

@ -64,11 +64,9 @@ pub fn routes() -> Vec<Route> {
use rocket::Route; use rocket::Route;
use rocket::response::status::BadRequest; use rocket::response::status::BadRequest;
use rocket_contrib::{Json, Value}; use rocket_contrib::Json;
use db::DbConn; use db::DbConn;
use db::models::*;
use util;
use auth::Headers; use auth::Headers;
@ -107,7 +105,7 @@ fn post_eq_domains(data: Json<EquivDomainData>, headers: Headers, conn: DbConn)
let excluded_globals = &data.ExcludedGlobalEquivalentDomains; let excluded_globals = &data.ExcludedGlobalEquivalentDomains;
let equivalent_domains = &data.EquivalentDomains; let equivalent_domains = &data.EquivalentDomains;
let mut user = headers.user; let user = headers.user;
//BODY. "{\"ExcludedGlobalEquivalentDomains\":[2],\"EquivalentDomains\":[[\"uoc.edu\",\"uoc.es\"]]}" //BODY. "{\"ExcludedGlobalEquivalentDomains\":[2],\"EquivalentDomains\":[[\"uoc.edu\",\"uoc.es\"]]}"

Datei anzeigen

@ -1,4 +1,3 @@
use rocket::Route;
use rocket::response::status::BadRequest; use rocket::response::status::BadRequest;
use rocket_contrib::{Json, Value}; use rocket_contrib::{Json, Value};
@ -6,7 +5,6 @@ use rocket_contrib::{Json, Value};
use data_encoding::BASE32; use data_encoding::BASE32;
use db::DbConn; use db::DbConn;
use db::models::*;
use util; use util;
use crypto; use crypto;

Datei anzeigen

@ -1,7 +1,6 @@
use std::io; use std::io;
use std::io::prelude::*; use std::io::prelude::*;
use std::fs::{create_dir_all, File}; use std::fs::{create_dir_all, File};
use std::path::Path;
use rocket::Route; use rocket::Route;
use rocket::response::Content; use rocket::response::Content;
@ -27,7 +26,7 @@ fn icon(domain: String) -> Content<Vec<u8>> {
// Get the icon, or fallback in case of error // Get the icon, or fallback in case of error
let icon = match get_icon_cached(&domain, &url) { let icon = match get_icon_cached(&domain, &url) {
Ok(icon) => icon, Ok(icon) => icon,
Err(e) => return Content(ContentType::PNG, get_fallback_icon()) Err(_) => return Content(ContentType::PNG, get_fallback_icon())
}; };
Content(ContentType::PNG, 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)?; create_dir_all(&CONFIG.icon_cache_folder)?;
let path = &format!("{}/{}.png", CONFIG.icon_cache_folder, key); 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) { match File::open(path) {
Ok(mut f) => { Ok(mut f) => {
let mut buffer = Vec::new(); 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, "")) Err(_) => return Err(io::Error::new(io::ErrorKind::NotFound, ""))
}; };
/// Save the currently downloaded icon // Save the currently downloaded icon
match File::create(path) { match File::create(path) {
Ok(mut f) => { f.write_all(&icon); } Ok(mut f) => { f.write_all(&icon); }
Err(_) => { /* Continue */ } Err(_) => { /* Continue */ }

Datei anzeigen

@ -71,12 +71,12 @@ fn login(connect_data: Form<ConnectData>, conn: DbConn) -> Result<Json, BadReque
if !user.check_totp_code(totp_code) { if !user.check_totp_code(totp_code) {
// Return error 400 // Return error 400
return err_json!(json!({ err_json!(json!({
"error" : "invalid_grant", "error" : "invalid_grant",
"error_description" : "Two factor required.", "error_description" : "Two factor required.",
"TwoFactorProviders" : [ 0 ], "TwoFactorProviders" : [ 0 ],
"TwoFactorProviders2" : { "0" : null } "TwoFactorProviders2" : { "0" : null }
})); }))
} }
// Let's only use the header and ignore the 'devicetype' parameter // 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 { impl<'f> FromForm<'f> for ConnectData {
type Error = String; 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(); let mut data = HashMap::new();
// Insert data into map // Insert data into map
for (key, value) in items { for (key, value) in items {
let decoded_key: String = match key.url_decode() { let decoded_key: String = match key.url_decode() {
Ok(decoded) => decoded, 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() { let decoded_value: String = match value.url_decode() {
Ok(decoded) => decoded, 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); data.insert(decoded_key.to_lowercase(), decoded_value);

Datei anzeigen

@ -3,9 +3,7 @@ use std::path::{Path, PathBuf};
use rocket::Route; use rocket::Route;
use rocket::response::NamedFile; use rocket::response::NamedFile;
use rocket_contrib::{Json, Value}; use rocket_contrib::Json;
use auth::Headers;
use CONFIG; use CONFIG;
@ -42,7 +40,7 @@ fn attachments(uuid: String, file: PathBuf) -> io::Result<NamedFile> {
#[get("/alive")] #[get("/alive")]
fn alive() -> Json<String> { fn alive() -> Json<String> {
use util::format_date; use util::format_date;
use chrono::{NaiveDateTime, Utc}; use chrono::Utc;
Json(format_date(&Utc::now().naive_utc())) Json(format_date(&Utc::now().naive_utc()))
} }

Datei anzeigen

@ -3,12 +3,10 @@
/// ///
use util::read_file; use util::read_file;
use std::path::Path;
use time::Duration; use time::Duration;
use jwt; use jwt;
use serde::ser::Serialize; use serde::ser::Serialize;
use serde::de::Deserialize;
use CONFIG; use CONFIG;
@ -89,7 +87,6 @@ pub struct JWTClaims {
/// ///
use rocket::Outcome; use rocket::Outcome;
use rocket::http::Status;
use rocket::request::{self, Request, FromRequest}; use rocket::request::{self, Request, FromRequest};
use db::DbConn; 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> { fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
let headers = request.headers(); let headers = request.headers();
/// Get device type // Get device type
let device_type = match headers.get_one("Device-Type") let device_type = match headers.get_one("Device-Type")
.map(|s| s.parse::<i32>()) { .map(|s| s.parse::<i32>()) {
Some(Ok(dt)) => Some(dt),// dt, Some(Ok(dt)) => Some(dt),// dt,
_ => None // return err_handler!("Device-Type is invalid or missing") _ => 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") { let access_token: &str = match request.headers().get_one("Authorization") {
Some(a) => { Some(a) => {
let split: Option<&str> = a.rsplit("Bearer ").next(); 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") 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) { let claims: JWTClaims = match decode_jwt(access_token) {
Ok(claims) => claims, Ok(claims) => claims,
Err(msg) => { Err(msg) => {

Datei anzeigen

@ -31,14 +31,11 @@ impl Attachment {
pub fn to_json(&self) -> JsonValue { pub fn to_json(&self) -> JsonValue {
use util::get_display_size; use util::get_display_size;
use CONFIG;
// TODO: Change all references to localhost (maybe put it in .env?) // TODO: Change all references to localhost (maybe put it in .env?)
let host = "http://localhost:8000"; let host = "http://localhost:8000";
let web_path = format!("{}/attachments/{}/{}", host, self.cipher_uuid, self.id); 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); let display_size = get_display_size(self.file_size);
json!({ json!({

Datei anzeigen

@ -1,5 +1,4 @@
use chrono::{NaiveDate, NaiveDateTime, Utc}; use chrono::{NaiveDateTime, Utc};
use time::Duration;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use uuid::Uuid; use uuid::Uuid;

Datei anzeigen

@ -1,8 +1,4 @@
use chrono::{NaiveDate, NaiveDateTime, Utc}; use chrono::{NaiveDateTime, Utc};
use time::Duration;
use serde_json::Value as JsonValue;
use uuid::Uuid;
use super::User; use super::User;

Datei anzeigen

@ -1,5 +1,4 @@
use chrono::{NaiveDate, NaiveDateTime, Utc}; use chrono::{NaiveDateTime, Utc};
use time::Duration;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use uuid::Uuid; use uuid::Uuid;

Datei anzeigen

@ -1,5 +1,4 @@
use chrono::{NaiveDate, NaiveDateTime, Utc}; use chrono::{NaiveDateTime, Utc};
use time::Duration;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use uuid::Uuid; use uuid::Uuid;
@ -100,7 +99,7 @@ impl User {
let decoded_secret = match BASE32.decode(totp_secret.as_bytes()) { let decoded_secret = match BASE32.decode(totp_secret.as_bytes()) {
Ok(s) => s, Ok(s) => s,
Err(e) => return false Err(_) => return false
}; };
let generated = totp_raw_now(&decoded_secret, 6, 0, 30, &HashType::SHA1); let generated = totp_raw_now(&decoded_secret, 6, 0, 30, &HashType::SHA1);

Datei anzeigen

@ -1,10 +1,9 @@
#![allow(dead_code, unused_variables, unused, unused_mut)] #![allow(unused)]
#![feature(plugin, custom_derive)] #![feature(plugin, custom_derive)]
#![cfg_attr(test, plugin(stainless))] #![cfg_attr(test, plugin(stainless))]
#![plugin(rocket_codegen)] #![plugin(rocket_codegen)]
extern crate rocket; extern crate rocket;
#[macro_use]
extern crate rocket_contrib; extern crate rocket_contrib;
extern crate reqwest; extern crate reqwest;
extern crate multipart; extern crate multipart;