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