Browse Source

Fix Clippy warnings

Paul Lietar 7 năm trước cách đây
mục cha
commit
64f9283b67
3 tập tin đã thay đổi với 7 bổ sung8 xóa
  1. 1 1
      src/apresolve.rs
  2. 4 5
      src/authentication/discovery.rs
  3. 2 2
      src/authentication/mod.rs

+ 1 - 1
src/apresolve.rs

@@ -16,7 +16,7 @@ pub struct APResolveData {
 pub fn apresolve(handle: &Handle) -> Box<Future<Item=String, Error=Error>> {
     let url = Url::parse(APRESOLVE_ENDPOINT).expect("invalid AP resolve URL");
 
-    let client = Client::new(&handle);
+    let client = Client::new(handle);
     let response = client.get(url);
 
     let body = response.and_then(|response| {

+ 4 - 5
src/authentication/discovery.rs

@@ -128,13 +128,13 @@ impl Discovery {
 
         let checksum_key = {
             let mut h = crypto::hmac::Hmac::new(crypto::sha1::Sha1::new(), &base_key);
-            h.input("checksum".as_bytes());
+            h.input(b"checksum");
             h.result().code().to_owned()
         };
 
         let encryption_key = {
             let mut h = crypto::hmac::Hmac::new(crypto::sha1::Sha1::new(), &base_key);
-            h.input("encryption".as_bytes());
+            h.input(b"encryption");
             h.result().code().to_owned()
         };
 
@@ -149,9 +149,8 @@ impl Discovery {
         let decrypted = {
             let mut data = vec![0u8; encrypted.len()];
             let mut cipher = crypto::aes::ctr(crypto::aes::KeySize::KeySize128,
-                                              &encryption_key[0..16],
-                                              &iv);
-            cipher.process(&encrypted, &mut data);
+                                              &encryption_key[0..16], iv);
+            cipher.process(encrypted, &mut data);
             String::from_utf8(data).unwrap()
         };
 

+ 2 - 2
src/authentication/mod.rs

@@ -153,7 +153,7 @@ fn deserialize_protobuf_enum<T, D>(de: D) -> Result<T, D::Error>
     where T: ProtobufEnum, D: serde::Deserializer {
 
     let v : i32 = try!(serde::Deserialize::deserialize(de));
-    T::from_i32(v).ok_or(serde::de::Error::custom("Invalid enum value"))
+    T::from_i32(v).ok_or_else(|| serde::de::Error::custom("Invalid enum value"))
 }
 
 fn serialize_base64<T, S>(v: &T, ser: S) -> Result<S::Ok, S::Error>
@@ -197,7 +197,7 @@ pub fn get_credentials(device_name: &str, device_id: &str,
 
         (None, _, None) => {
             info!("No username provided and no stored credentials, starting discovery ...");
-            discovery_login(device_name.clone(), device_id.clone()).unwrap()
+            discovery_login(device_name, device_id).unwrap()
         }
     }
 }