Fix clippy warnings Signed-off-by: constantoine <cleo.rebert-ext@treezor.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
diff --git a/src/lib.rs b/src/lib.rs
index 339f914..a8d2bfe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -54,7 +54,6 @@ mod url_error;
pub use secret::{Secret, SecretParseError};
pub use url_error::TotpUrlError;
pub use rfc::{Rfc6238, Rfc6238Error};
-use base32;
use constant_time_eq::constant_time_eq;
@@ -64,12 +63,10 @@ use serde::{Deserialize, Serialize};
use core::fmt;
#[cfg(feature = "qr")]
-use {base64, image::Luma, qrcodegen};
+use image::Luma;
#[cfg(feature = "otpauth")]
use url::{Host, Url};
-#[cfg(feature = "otpauth")]
-use urlencoding;
use hmac::Mac;
use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};
@@ -185,7 +182,7 @@ impl Default for TOTP {
#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
impl Default for TOTP {
fn default() -> Self {
- return TOTP::new(Algorithm::SHA1, 6, 1, 30, Secret::generate_secret().to_bytes().unwrap(), None, "".to_string()).unwrap()
+ TOTP::new(Algorithm::SHA1, 6, 1, 30, Secret::generate_secret().to_bytes().unwrap(), None, "".to_string()).unwrap()
}
}
@@ -345,7 +342,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
/// Generate a TOTP from the standard otpauth URL
#[cfg(feature = "otpauth")]
pub fn from_url<S: AsRef<str>>(url: S) -> Result<TOTP<Vec<u8>>, TotpUrlError> {
- let url = Url::parse(url.as_ref()).map_err(|err| TotpUrlError::Url(err))?;
+ let url = Url::parse(url.as_ref()).map_err(TotpUrlError::Url)?;
if url.scheme() != "otpauth" {
return Err(TotpUrlError::Scheme(url.scheme().to_string()));
}
@@ -363,7 +360,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
let path = url.path().trim_start_matches('/');
if path.contains(':') {
let parts = path.split_once(':').unwrap();
- issuer = Some(urlencoding::decode(parts.0.to_owned().as_str()).map_err(|_| TotpUrlError::IssuerDecoding(parts.0.to_owned().to_string()))?.to_string());
+ issuer = Some(urlencoding::decode(parts.0.to_owned().as_str()).map_err(|_| TotpUrlError::IssuerDecoding(parts.0.to_owned()))?.to_string());
account_name = parts.1.trim_start_matches(':').to_owned();
} else {
account_name = path.to_owned();
@@ -390,7 +387,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
"secret" => {
secret =
base32::decode(base32::Alphabet::RFC4648 { padding: false }, value.as_ref())
- .ok_or(TotpUrlError::Secret(value.to_string()))?;
+ .ok_or_else(|| TotpUrlError::Secret(value.to_string()))?;
}
"issuer" => {
let param_issuer = value.parse::<String>().map_err(|_| TotpUrlError::Issuer(value.to_string()))?;
@@ -416,20 +413,19 @@ impl<T: AsRef<[u8]>> TOTP<T> {
/// Secret will be base 32'd without padding, as per RFC.
#[cfg(feature = "otpauth")]
pub fn get_url(&self) -> String {
- let label: String;
+
let account_name: String = urlencoding::encode(self.account_name.as_str()).to_string();
+ let mut label: String = format!("{}?", account_name);
if self.issuer.is_some() {
let issuer: String = urlencoding::encode(self.issuer.as_ref().unwrap().as_str()).to_string();
label = format!("{0}:{1}?issuer={0}&", issuer, account_name);
- } else {
- label = format!("{}?", account_name);
}
format!(
"otpauth://totp/{}secret={}&digits={}&algorithm={}",
label,
self.get_secret_base32(),
- self.digits.to_string(),
+ self.digits,
self.algorithm,
)
}
diff --git a/src/rfc.rs b/src/rfc.rs
index f5f763c..2bca3e4 100644
--- a/src/rfc.rs
+++ b/src/rfc.rs
@@ -324,7 +324,7 @@ mod tests {
)
.unwrap();
let totp = TOTP::try_from(rfc);
- assert!(!totp.is_err());
+ assert!(totp.is_ok());
}
#[test]
diff --git a/src/secret.rs b/src/secret.rs
index 1b2351d..609849f 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -107,7 +107,7 @@ impl PartialEq for Secret {
#[cfg(feature = "gen_secret")]
impl Default for Secret {
fn default() -> Self {
- return Secret::generate_secret()
+ Secret::generate_secret()
}
}