chore: Use core implementation to extract the signature and public key
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
f4df5b26d3
commit
5ca23c8af5
2 changed files with 21 additions and 13 deletions
|
@ -16,10 +16,12 @@
|
|||
|
||||
//! Request signature middleware.
|
||||
|
||||
use oxidetalis_core::types::{PublicKey, Signature};
|
||||
use salvo::{
|
||||
handler,
|
||||
http::{Body, StatusCode},
|
||||
Depot,
|
||||
Extractible,
|
||||
FlowCtrl,
|
||||
Request,
|
||||
Response,
|
||||
|
@ -54,7 +56,7 @@ pub async fn signature_check(
|
|||
}
|
||||
};
|
||||
|
||||
let signature = match utils::extract_signature(req) {
|
||||
let signature = match Signature::extract(req).await {
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
write_err(&err.to_string(), UNAUTHORIZED);
|
||||
|
@ -62,7 +64,7 @@ pub async fn signature_check(
|
|||
}
|
||||
};
|
||||
|
||||
let sender_public_key = match utils::extract_public_key(req) {
|
||||
let sender_public_key = match PublicKey::extract(req).await {
|
||||
Ok(k) => k,
|
||||
Err(err) => {
|
||||
write_err(&err.to_string(), UNAUTHORIZED);
|
||||
|
|
|
@ -111,20 +111,26 @@ impl EndpointArgRegister for CorePublicKey {
|
|||
|
||||
impl<'ex> Extractible<'ex> for Signature {
|
||||
fn metadata() -> &'ex ExtractMetadata {
|
||||
unreachable!(
|
||||
"
|
||||
`Extractible` is required to implement `ToParameters` for `Signature`, but \
|
||||
Salvo does not need it actually, see https://github.com/salvo-rs/salvo/issues/838"
|
||||
)
|
||||
static METADATA: ExtractMetadata = ExtractMetadata::new("");
|
||||
&METADATA
|
||||
}
|
||||
|
||||
#[allow(refining_impl_trait)]
|
||||
async fn extract(_: &'ex mut Request) -> Result<Self, StatusError> {
|
||||
unreachable!(
|
||||
"
|
||||
`Extractible` is required to implement `ToParameters` for `Signature`, but \
|
||||
Salvo does not need it actually, see https://github.com/salvo-rs/salvo/issues/838"
|
||||
)
|
||||
async fn extract(req: &'ex mut Request) -> Result<Self, StatusError> {
|
||||
extract_header(req, crate::SIGNATURE_HEADER)
|
||||
.and_then(|sig| {
|
||||
Signature::from_str(sig).map_err(|err| {
|
||||
StatusError::unauthorized()
|
||||
.brief("Invalid signature")
|
||||
.cause(err.to_string())
|
||||
})
|
||||
})
|
||||
.map_err(|err| {
|
||||
StatusError::unauthorized().brief(err.brief).cause(
|
||||
err.cause
|
||||
.expect("The cause was set when we extract the header"),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue