chore: Let salvo extract the public key and the signature
All checks were successful
DCO checker / DCO checker (pull_request) Successful in 4s
Rust CI / Rust CI (pull_request) Successful in 4m22s

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-28 12:27:03 +03:00
parent c137129488
commit 71d63580bf
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -21,10 +21,10 @@ use salvo::{
handler,
http::{Body, StatusCode},
Depot,
Extractible,
FlowCtrl,
Request,
Response,
Writer,
};
use crate::{extensions::DepotExt, utils};
@ -39,6 +39,8 @@ pub async fn signature_check(
res: &mut Response,
depot: &mut Depot,
ctrl: &mut FlowCtrl,
sender_public_key: PublicKey,
signature: Signature,
) {
const UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED;
let mut write_err =
@ -56,22 +58,6 @@ pub async fn signature_check(
}
};
let signature = match Signature::extract(req).await {
Ok(s) => s,
Err(err) => {
write_err(&err.to_string(), UNAUTHORIZED);
return;
}
};
let sender_public_key = match PublicKey::extract(req).await {
Ok(k) => k,
Err(err) => {
write_err(&err.to_string(), UNAUTHORIZED);
return;
}
};
if !utils::is_valid_nonce(&signature, &depot.nonce_cache()).await
|| !depot.config().server.private_key.verify(
data.as_bytes(),