Skip to content

Commit

Permalink
fix(clippy): remove is_64
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 3, 2023
1 parent 7fc08df commit c90addf
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions viz-core/src/middleware/csrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
Some(raw_token) => base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(raw_token)
.ok()
.filter(is_64)
.filter(|b| b.len() == 64)
.map(unmask::<32>)
.map(Option::Some)
.ok_or_else(|| {
Expand Down Expand Up @@ -252,10 +252,13 @@ pub fn generate(secret: &[u8], otp: Vec<u8>) -> Vec<u8> {
/// Verifys Token with a secret
#[must_use]
pub fn verify(secret: &[u8], raw_token: String) -> bool {
if let Ok(token) = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(raw_token) {
return is_64(&token) && secret == unmask::<32>(token);
}
false
base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(raw_token)
.ok()
.filter(|b| b.len() == 64)
.map(unmask::<32>)
.filter(|t| t == secret)
.is_some()
}

/// Retures masked token
Expand All @@ -282,10 +285,6 @@ fn unmask<const N: usize>(mut token: Vec<u8>) -> Vec<u8> {
secret
}

fn is_64(buf: &Vec<u8>) -> bool {
buf.len() == 64
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit c90addf

Please sign in to comment.