From 71d63580bfbe7720b2212e94d72fd0c5e707db44 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Sun, 28 Jul 2024 12:27:03 +0300 Subject: [PATCH] chore: Let salvo extract the public key and the signature Signed-off-by: Awiteb --- .../oxidetalis/src/middlewares/signature.rs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/oxidetalis/src/middlewares/signature.rs b/crates/oxidetalis/src/middlewares/signature.rs index e5d019b..2729873 100644 --- a/crates/oxidetalis/src/middlewares/signature.rs +++ b/crates/oxidetalis/src/middlewares/signature.rs @@ -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(),