refactor: Use PublicKey and Signature as parameters #33

Manually merged
awiteb merged 9 commits from awiteb/public-key_and_siganture_as_parameters into master 2024-07-28 11:56:46 +02:00 AGit
Showing only changes of commit 71d63580bf - Show all commits

View file

@ -21,10 +21,10 @@ use salvo::{
handler, handler,
http::{Body, StatusCode}, http::{Body, StatusCode},
Depot, Depot,
Extractible,
FlowCtrl, FlowCtrl,
Request, Request,
Response, Response,
Writer,
}; };
use crate::{extensions::DepotExt, utils}; use crate::{extensions::DepotExt, utils};
@ -39,6 +39,8 @@ pub async fn signature_check(
res: &mut Response, res: &mut Response,
depot: &mut Depot, depot: &mut Depot,
ctrl: &mut FlowCtrl, ctrl: &mut FlowCtrl,
sender_public_key: PublicKey,
signature: Signature,
) { ) {
const UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED; const UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED;
let mut write_err = 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 if !utils::is_valid_nonce(&signature, &depot.nonce_cache()).await
|| !depot.config().server.private_key.verify( || !depot.config().server.private_key.verify(
data.as_bytes(), data.as_bytes(),