feat(auth): Add support for partial-auth, by facilitating injection of authentication parameters in headers (#4802)

Co-authored-by: Jagan <jaganelavarasan@gmail.com>
This commit is contained in:
Nishant Joshi
2024-08-01 14:57:39 +05:30
committed by GitHub
parent 5e1eb4af86
commit 1d4c87a9e3
31 changed files with 523 additions and 103 deletions

View File

@ -238,6 +238,43 @@ impl VerifySignature for HmacSha512 {
}
}
///
/// Blake3
#[derive(Debug)]
pub struct Blake3(String);
impl Blake3 {
/// Create a new instance of Blake3 with a key
pub fn new(key: impl Into<String>) -> Self {
Self(key.into())
}
}
impl SignMessage for Blake3 {
fn sign_message(
&self,
secret: &[u8],
msg: &[u8],
) -> CustomResult<Vec<u8>, errors::CryptoError> {
let key = blake3::derive_key(&self.0, secret);
let output = blake3::keyed_hash(&key, msg).as_bytes().to_vec();
Ok(output)
}
}
impl VerifySignature for Blake3 {
fn verify_signature(
&self,
secret: &[u8],
signature: &[u8],
msg: &[u8],
) -> CustomResult<bool, errors::CryptoError> {
let key = blake3::derive_key(&self.0, secret);
let output = blake3::keyed_hash(&key, msg);
Ok(output.as_bytes() == signature)
}
}
/// Represents the GCM-AES-256 algorithm
#[derive(Debug)]
pub struct GcmAes256;