[pmg-devel] [PATCH proxmox 5/6] tfa: clippy fixes
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Nov 26 14:55:23 CET 2021
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
proxmox-tfa/src/api/methods.rs | 20 ++++++++++----------
proxmox-tfa/src/api/mod.rs | 6 +++---
proxmox-tfa/src/api/recovery.rs | 4 ++--
proxmox-tfa/src/api/serde_tools.rs | 8 ++++----
proxmox-tfa/src/api/webauthn.rs | 6 +++---
proxmox-tfa/src/totp.rs | 14 ++++++++------
proxmox-tfa/src/u2f.rs | 2 +-
7 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/proxmox-tfa/src/api/methods.rs b/proxmox-tfa/src/api/methods.rs
index b63d56e..08905da 100644
--- a/proxmox-tfa/src/api/methods.rs
+++ b/proxmox-tfa/src/api/methods.rs
@@ -142,7 +142,7 @@ pub fn get_tfa_entry(config: &TfaConfig, userid: &str, id: &str) -> Option<Typed
Some(
match {
// scope to prevent the temporary iter from borrowing across the whole match
- let entry = tfa_id_iter(&user_data).find(|(_ty, _index, entry_id)| id == *entry_id);
+ let entry = tfa_id_iter(user_data).find(|(_ty, _index, entry_id)| id == *entry_id);
entry.map(|(ty, index, _)| (ty, index))
} {
Some((TfaType::Recovery, _)) => match user_data.recovery() {
@@ -155,21 +155,20 @@ pub fn get_tfa_entry(config: &TfaConfig, userid: &str, id: &str) -> Option<Typed
Some((TfaType::Totp, index)) => {
TypedTfaInfo {
ty: TfaType::Totp,
- // `into_iter().nth()` to *move* out of it
- info: user_data.totp.iter().nth(index).unwrap().info.clone(),
+ info: user_data.totp.get(index).unwrap().info.clone(),
}
}
Some((TfaType::Webauthn, index)) => TypedTfaInfo {
ty: TfaType::Webauthn,
- info: user_data.webauthn.iter().nth(index).unwrap().info.clone(),
+ info: user_data.webauthn.get(index).unwrap().info.clone(),
},
Some((TfaType::U2f, index)) => TypedTfaInfo {
ty: TfaType::U2f,
- info: user_data.u2f.iter().nth(index).unwrap().info.clone(),
+ info: user_data.u2f.get(index).unwrap().info.clone(),
},
Some((TfaType::Yubico, index)) => TypedTfaInfo {
ty: TfaType::Yubico,
- info: user_data.yubico.iter().nth(index).unwrap().info.clone(),
+ info: user_data.yubico.get(index).unwrap().info.clone(),
},
None => return None,
},
@@ -195,7 +194,7 @@ pub fn delete_tfa(config: &mut TfaConfig, userid: &str, id: &str) -> Result<bool
match {
// scope to prevent the temporary iter from borrowing across the whole match
- let entry = tfa_id_iter(&user_data).find(|(_, _, entry_id)| id == *entry_id);
+ let entry = tfa_id_iter(user_data).find(|(_, _, entry_id)| id == *entry_id);
entry.map(|(ty, index, _)| (ty, index))
} {
Some((TfaType::Recovery, _)) => user_data.recovery = None,
@@ -308,6 +307,7 @@ fn need_description(description: Option<String>) -> Result<String, Error> {
/// Permissions for accessing `userid` must have been verified by the caller.
///
/// The caller must have already verified the user's password!
+#[allow(clippy::too_many_arguments)]
pub fn add_tfa_entry<A: OpenUserChallengeData>(
config: &mut TfaConfig,
access: A,
@@ -354,7 +354,7 @@ pub fn add_tfa_entry<A: OpenUserChallengeData>(
bail!("generating recovery tokens does not allow additional parameters");
}
- let recovery = config.add_recovery(&userid)?;
+ let recovery = config.add_recovery(userid)?;
Ok(TfaUpdateInfo {
id: Some("recovery".to_string()),
@@ -451,7 +451,7 @@ fn add_webauthn<A: OpenUserChallengeData>(
None => config
.webauthn_registration_challenge(
access,
- &userid,
+ userid,
need_description(description)?,
origin,
)
@@ -464,7 +464,7 @@ fn add_webauthn<A: OpenUserChallengeData>(
format_err!("missing 'value' parameter (webauthn challenge response missing)")
})?;
config
- .webauthn_registration_finish(access, &userid, &challenge, &value, origin)
+ .webauthn_registration_finish(access, userid, &challenge, &value, origin)
.map(TfaUpdateInfo::id)
}
}
diff --git a/proxmox-tfa/src/api/mod.rs b/proxmox-tfa/src/api/mod.rs
index b591a23..1f9fb2c 100644
--- a/proxmox-tfa/src/api/mod.rs
+++ b/proxmox-tfa/src/api/mod.rs
@@ -247,13 +247,13 @@ impl TfaConfig {
TfaResponse::U2f(value) => match &challenge.u2f {
Some(challenge) => {
let u2f = check_u2f(&self.u2f)?;
- user.verify_u2f(access.clone(), userid, u2f, &challenge.challenge, value)
+ user.verify_u2f(access, userid, u2f, &challenge.challenge, value)
}
None => bail!("no u2f factor available for user '{}'", userid),
},
TfaResponse::Webauthn(value) => {
let webauthn = check_webauthn(&self.webauthn, origin)?;
- user.verify_webauthn(access.clone(), userid, webauthn, value)
+ user.verify_webauthn(access, userid, webauthn, value)
}
TfaResponse::Recovery(value) => {
user.verify_recovery(&value)?;
@@ -587,7 +587,7 @@ impl TfaUserData {
None => None,
},
u2f: match u2f {
- Some(u2f) => self.u2f_challenge(access.clone(), userid, u2f)?,
+ Some(u2f) => self.u2f_challenge(access, userid, u2f)?,
None => None,
},
yubico: self.yubico.iter().any(|e| e.info.enable),
diff --git a/proxmox-tfa/src/api/recovery.rs b/proxmox-tfa/src/api/recovery.rs
index 9af2873..92c0e9d 100644
--- a/proxmox-tfa/src/api/recovery.rs
+++ b/proxmox-tfa/src/api/recovery.rs
@@ -12,7 +12,7 @@ fn getrandom(mut buffer: &mut [u8]) -> Result<(), io::Error> {
libc::getrandom(
buffer.as_mut_ptr() as *mut libc::c_void,
buffer.len() as libc::size_t,
- 0 as libc::c_uint,
+ 0,
)
};
@@ -49,7 +49,7 @@ impl Recovery {
getrandom(&mut secret)?;
let mut this = Self {
- secret: hex::encode(&secret).to_string(),
+ secret: hex::encode(&secret),
entries: Vec::with_capacity(10),
created: proxmox_time::epoch_i64(),
};
diff --git a/proxmox-tfa/src/api/serde_tools.rs b/proxmox-tfa/src/api/serde_tools.rs
index 1f307a2..b9f73d7 100644
--- a/proxmox-tfa/src/api/serde_tools.rs
+++ b/proxmox-tfa/src/api/serde_tools.rs
@@ -11,7 +11,7 @@ use serde::Deserialize;
pub struct FoldSeqVisitor<T, Out, F, Init>
where
Init: FnOnce(Option<usize>) -> Out,
- F: Fn(&mut Out, T) -> (),
+ F: Fn(&mut Out, T),
{
init: Option<Init>,
closure: F,
@@ -22,7 +22,7 @@ where
impl<T, Out, F, Init> FoldSeqVisitor<T, Out, F, Init>
where
Init: FnOnce(Option<usize>) -> Out,
- F: Fn(&mut Out, T) -> (),
+ F: Fn(&mut Out, T),
{
pub fn new(expecting: &'static str, init: Init, closure: F) -> Self {
Self {
@@ -37,7 +37,7 @@ where
impl<'de, T, Out, F, Init> serde::de::Visitor<'de> for FoldSeqVisitor<T, Out, F, Init>
where
Init: FnOnce(Option<usize>) -> Out,
- F: Fn(&mut Out, T) -> (),
+ F: Fn(&mut Out, T),
T: Deserialize<'de>,
{
type Value = Out;
@@ -104,7 +104,7 @@ pub fn fold<'de, T, Out, Init, Fold>(
) -> FoldSeqVisitor<T, Out, Fold, Init>
where
Init: FnOnce(Option<usize>) -> Out,
- Fold: Fn(&mut Out, T) -> (),
+ Fold: Fn(&mut Out, T),
T: Deserialize<'de>,
{
FoldSeqVisitor::new(expected, init, fold)
diff --git a/proxmox-tfa/src/api/webauthn.rs b/proxmox-tfa/src/api/webauthn.rs
index aed2885..4e90007 100644
--- a/proxmox-tfa/src/api/webauthn.rs
+++ b/proxmox-tfa/src/api/webauthn.rs
@@ -41,9 +41,9 @@ impl std::ops::DerefMut for OriginUrl {
}
}
-impl Into<String> for OriginUrl {
- fn into(self) -> String {
- self.0.into()
+impl From<OriginUrl> for String {
+ fn from(url: OriginUrl) -> String {
+ url.0.into()
}
}
diff --git a/proxmox-tfa/src/totp.rs b/proxmox-tfa/src/totp.rs
index d2e009b..1e342c4 100644
--- a/proxmox-tfa/src/totp.rs
+++ b/proxmox-tfa/src/totp.rs
@@ -20,9 +20,9 @@ pub enum Algorithm {
Sha512,
}
-impl Into<MessageDigest> for Algorithm {
- fn into(self) -> MessageDigest {
- match self {
+impl From<Algorithm> for MessageDigest {
+ fn from(algo: Algorithm) -> MessageDigest {
+ match algo {
Algorithm::Sha1 => MessageDigest::sha1(),
Algorithm::Sha256 => MessageDigest::sha256(),
Algorithm::Sha512 => MessageDigest::sha512(),
@@ -343,7 +343,7 @@ impl std::str::FromStr for Totp {
// FIXME: Also split on "%3A" / "%3a"
let mut account = account.splitn(2, |&b| b == b':');
let first_part = percent_decode(
- &account
+ account
.next()
.ok_or_else(|| anyhow!("missing account in otpauth uri"))?,
)
@@ -364,13 +364,13 @@ impl std::str::FromStr for Totp {
for parts in uri.split(|&b| b == b'&') {
let mut parts = parts.splitn(2, |&b| b == b'=');
let key = percent_decode(
- &parts
+ parts
.next()
.ok_or_else(|| anyhow!("bad key in otpauth uri"))?,
)
.decode_utf8()?;
let value = percent_decode(
- &parts
+ parts
.next()
.ok_or_else(|| anyhow!("bad value in otpauth uri"))?,
);
@@ -467,6 +467,8 @@ impl PartialEq<&str> for TotpValue {
return false;
}
+ // I don't trust that `.parse()` never starts accepting `0x` prefixes so:
+ #[allow(clippy::from_str_radix_10)]
match u32::from_str_radix(*other, 10) {
Ok(value) => self.value() == value,
Err(_) => false,
diff --git a/proxmox-tfa/src/u2f.rs b/proxmox-tfa/src/u2f.rs
index 84fea41..9175e14 100644
--- a/proxmox-tfa/src/u2f.rs
+++ b/proxmox-tfa/src/u2f.rs
@@ -579,7 +579,7 @@ mod bytes_as_base64url_nopad {
pub fn serialize<S: Serializer>(data: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&base64::encode_config(
- data.as_ref(),
+ data,
base64::URL_SAFE_NO_PAD,
))
}
--
2.30.2
More information about the pmg-devel
mailing list