Skip to content

Commit

Permalink
fix(test): fix test on safe
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Apr 25, 2024
1 parent 6716123 commit ea0ff66
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/utils/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ring::agreement::{agree_ephemeral, EphemeralPrivateKey, PublicKey, UnparsedP

use ring::aead::AES_128_GCM;
use ring::rand::{SecureRandom, SystemRandom};
// use scrypt::{scrypt, Params};
use scrypt::{scrypt, Params};
use sha2::Sha256;

use crate::exceptions::Exception;
Expand Down Expand Up @@ -52,10 +52,13 @@ pub fn generate_key_pair() -> Result<(EphemeralSecret, PublicKey), Exception> {
///
/// let salt = generate_random_salt();
/// let (private_key, public_key) = generate_key_pair().unwrap();
///
///
/// #[cfg(feature = "unsafe")]
/// let mut shared_key = SharedKey::new(&private_key, &public_key);
///
/// #[cfg(feature = "unsafe")]
/// shared_key.hkdf(&salt);
/// #[cfg(feature = "unsafe")]
/// shared_key.scrypt(&salt);
/// ```
pub struct SharedKey {
Expand All @@ -80,18 +83,18 @@ impl SharedKey {
}
}

// pub fn scrypt(&mut self, salt: &[u8]) -> Result<Vec<u8>> {
// let mut aes_key = [0u8; 16];
// match scrypt(
// &self.shared_key.raw_secret_bytes().to_vec(),
// &salt,
// &Params::new(12, 8, 1, 16).unwrap(),
// &mut aes_key,
// ) {
// Ok(()) => Ok(aes_key.to_vec()),
// Err(error) => Err(Exception::InvalidOutputLen { error }.into()),
// }
// }
pub fn scrypt(&mut self, salt: &[u8]) -> Result<Vec<u8>> {
let mut aes_key = [0u8; 16];
match scrypt(
&self.shared_key,
&salt,
&Params::new(12, 8, 1, 16).unwrap(),
&mut aes_key,
) {
Ok(()) => Ok(aes_key.to_vec()),
Err(error) => Err(Exception::InvalidOutputLen { error }.into()),
}
}

pub fn hkdf(&mut self, salt: &[u8]) -> Result<Vec<u8>> {
let key = Hkdf::<Sha256>::new(Some(salt), &self.shared_key);
Expand Down

0 comments on commit ea0ff66

Please sign in to comment.