From 672b84710e00e8e2a0ca5564825ecc02c0ab142d Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 23 Jul 2024 22:21:56 +0300
Subject: [PATCH] remove: Remove `is_valid_signature` util
Signed-off-by: Awiteb
---
crates/oxidetalis/src/middlewares/signature.rs | 7 +++----
crates/oxidetalis/src/utils.rs | 13 +------------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/crates/oxidetalis/src/middlewares/signature.rs b/crates/oxidetalis/src/middlewares/signature.rs
index b191d64..f108f4a 100644
--- a/crates/oxidetalis/src/middlewares/signature.rs
+++ b/crates/oxidetalis/src/middlewares/signature.rs
@@ -71,11 +71,10 @@ pub async fn signature_check(
};
if !utils::is_valid_nonce(&signature, &depot.nonce_cache()).await
- || !utils::is_valid_signature(
- &sender_public_key,
- &depot.config().server.private_key,
- &signature,
+ || !depot.config().server.private_key.verify(
data.as_bytes(),
+ &signature,
+ &sender_public_key,
)
{
write_err("Invalid signature", UNAUTHORIZED);
diff --git a/crates/oxidetalis/src/utils.rs b/crates/oxidetalis/src/utils.rs
index 1f4ef34..2bd316b 100644
--- a/crates/oxidetalis/src/utils.rs
+++ b/crates/oxidetalis/src/utils.rs
@@ -22,8 +22,7 @@ use chrono::Utc;
use logcall::logcall;
use oxidetalis_config::Postgres;
use oxidetalis_core::{
- cipher::K256Secret,
- types::{PrivateKey, PublicKey, Signature},
+ types::{PublicKey, Signature},
PUBLIC_KEY_HEADER,
SIGNATURE_HEADER,
};
@@ -50,16 +49,6 @@ pub(crate) async fn is_valid_nonce(signature: &Signature, nonce_cache: &NonceCac
new_timestamp && unused_nonce
}
-/// Returns true if the given signature is valid.
-pub(crate) fn is_valid_signature(
- signer: &PublicKey,
- private_key: &PrivateKey,
- signature: &Signature,
- data: &[u8],
-) -> bool {
- K256Secret::from_privkey(private_key).verify(data, signature, signer)
-}
-
/// Extract the sender public key from the request
///
/// Returns the public key of the sender extracted from the request, or the