Browse Source

fix(clippy): few refactors

pull/7370/head
Raphael Roumezin 4 weeks ago
parent
commit
3b669264bb
No known key found for this signature in database GPG Key ID: 91D7A94FE35B7922
  1. 35
      src/api/core/webauthn.rs
  2. 4
      src/api/identity.rs

35
src/api/core/webauthn.rs

@ -135,43 +135,43 @@ async fn post_webauthn_attestation_options(
challenge.public_key.pub_key_cred_params = vec![ challenge.public_key.pub_key_cred_params = vec![
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::ES256 as i64, alg: COSEAlgorithm::ES256 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::ES384 as i64, alg: COSEAlgorithm::ES384 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::ES512 as i64, alg: COSEAlgorithm::ES512 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::RS256 as i64, alg: COSEAlgorithm::RS256 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::RS384 as i64, alg: COSEAlgorithm::RS384 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::RS512 as i64, alg: COSEAlgorithm::RS512 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::PS256 as i64, alg: COSEAlgorithm::PS256 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::PS384 as i64, alg: COSEAlgorithm::PS384 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::PS512 as i64, alg: COSEAlgorithm::PS512 as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
PubKeyCredParams { PubKeyCredParams {
alg: COSEAlgorithm::EDDSA as i64, alg: COSEAlgorithm::EDDSA as i64,
type_: "public-key".to_string(), type_: "public-key".to_owned(),
}, },
]; ];
@ -216,13 +216,12 @@ async fn post_webauthn(
// Retrieve and delete the saved challenge state from the database // Retrieve and delete the saved challenge state from the database
let type_ = TwoFactorType::WebauthnPasskeyRegisterChallenge as i32; let type_ = TwoFactorType::WebauthnPasskeyRegisterChallenge as i32;
let credential = match TwoFactor::find_by_user_and_type(&user.uuid, type_, &conn).await { let credential = if let Some(tf) = TwoFactor::find_by_user_and_type(&user.uuid, type_, &conn).await {
Some(tf) => { let state: PasskeyRegistration = serde_json::from_str(&tf.data)?;
let state: PasskeyRegistration = serde_json::from_str(&tf.data)?; tf.delete(&conn).await?;
tf.delete(&conn).await?; WEBAUTHN_PASSWORDLESS.finish_passkey_registration(&data.device_response.into(), &state)?
WEBAUTHN_PASSWORDLESS.finish_passkey_registration(&data.device_response.into(), &state)? } else {
} err!("No registration challenge found. Please try again.")
None => err!("No registration challenge found. Please try again."),
}; };
WebauthnCredential::new( WebauthnCredential::new(
@ -256,7 +255,7 @@ async fn post_webauthn_delete(
data.validate(&user, false, &conn).await?; data.validate(&user, false, &conn).await?;
WebauthnCredential::delete_by_uuid_and_user(&WebauthnCredentialId::from(uuid.to_string()), &user.uuid, &conn) WebauthnCredential::delete_by_uuid_and_user(&WebauthnCredentialId::from(uuid.to_owned()), &user.uuid, &conn)
.await?; .await?;
Ok(Status::Ok) Ok(Status::Ok)

4
src/api/identity.rs

@ -581,12 +581,12 @@ async fn webauthn_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &
raw_state.get_mut("ast").and_then(|v| v.get_mut("credentials")).and_then(|v| v.as_array_mut()) raw_state.get_mut("ast").and_then(|v| v.get_mut("credentials")).and_then(|v| v.as_array_mut())
{ {
credentials.clear(); credentials.clear();
for (_, passkey) in user_webauthn_credentials.iter() { for (_, passkey) in &user_webauthn_credentials {
let passkey_owned: Passkey = passkey.clone(); let passkey_owned: Passkey = passkey.clone();
let cred = <webauthn_rs::prelude::Credential>::from(passkey_owned); let cred = <webauthn_rs::prelude::Credential>::from(passkey_owned);
credentials.push(serde_json::to_value(&cred)?); credentials.push(serde_json::to_value(&cred)?);
} }
}; }
serde_json::from_value(raw_state)? serde_json::from_value(raw_state)?
} else { } else {
err!( err!(

Loading…
Cancel
Save