refactor: Use PublicKey
and Signature
as parameters #33
1 changed files with 3 additions and 17 deletions
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue