From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH proxmox 5/6] tfa: clippy fixes
Date: Fri, 26 Nov 2021 14:55:23 +0100 [thread overview]
Message-ID: <20211126135524.117846-20-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20211126135524.117846-1-w.bumiller@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@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
next prev parent reply other threads:[~2021-11-26 13:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-26 13:55 [pmg-devel] [PATCH multiple 0/7] PMG TFA support Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH api 1/6] add tfa.json and its lock methods Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH api 2/6] add PMG::TFAConfig module Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH api 3/6] add TFA API Wolfgang Bumiller
2021-11-26 17:29 ` Stoiko Ivanov
2021-11-26 13:55 ` [pmg-devel] [PATCH api 4/6] add tfa config api Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH api 5/6] implement tfa authentication Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH api 6/6] provide qrcode.min.js from libjs-qrcodejs Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH gui] add TFA components Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 1/7] pve: bump perlmod to 0.9 Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 2/7] pve: update to proxmox-tfa 2.0 Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 3/7] pve: bump d/control Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 4/7] import pmg-rs Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 5/7] pmg: bump perlmod to 0.9 Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 6/7] pmg: add tfa module Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH perl-rs 7/7] pmg: bump d/control Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH proxmox 1/6] tfa: fix typo in docs Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH proxmox 2/6] tfa: add WebauthnConfig::digest method Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH proxmox 3/6] tfa: let OriginUrl deref to its inner Url, add FromStr impl Wolfgang Bumiller
2021-11-26 13:55 ` [pmg-devel] [PATCH proxmox 4/6] tfa: make configured webauthn origin optional Wolfgang Bumiller
2021-11-26 13:55 ` Wolfgang Bumiller [this message]
2021-11-26 13:55 ` [pmg-devel] [PATCH proxmox 6/6] bump proxmox-tfa to 2.0.0-1 Wolfgang Bumiller
2021-11-26 17:34 ` [pmg-devel] [PATCH multiple 0/7] PMG TFA support Stoiko Ivanov
2021-11-28 21:17 ` [pmg-devel] applied-series: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211126135524.117846-20-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.