Skip to content

Commit

Permalink
[wip] resolve discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
tuta-sudipg authored and ganthern committed Oct 10, 2024
1 parent d898ddc commit 6221be6
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 312 deletions.
22 changes: 22 additions & 0 deletions tuta-sdk/rust/sdk/src/crypto/randomizer_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,26 @@ pub mod test_util {
pub fn make_thread_rng_facade() -> RandomizerFacade {
RandomizerFacade::from_core(rand::rngs::OsRng {})
}

#[derive(Clone)]
pub struct DeterministicRng(pub u8);
impl RngCore for DeterministicRng {
fn next_u32(&mut self) -> u32 {
self.0.into()
}

fn next_u64(&mut self) -> u64 {
self.0.into()
}

fn fill_bytes(&mut self, dest: &mut [u8]) {
dest.fill(self.0)
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
self.fill_bytes(dest);
Ok(())
}
}
impl CryptoRng for DeterministicRng {}
}
12 changes: 5 additions & 7 deletions tuta-sdk/rust/sdk/src/crypto_entity_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ pub struct CryptoEntityClient {
instance_mapper: Arc<InstanceMapper>,
}

impl CryptoEntityClient {
pub fn get_crypto_facade(&self) -> &Arc<CryptoFacade> {
&self.crypto_facade
}
}

#[cfg_attr(test, mockall::automock)]
impl CryptoEntityClient {
pub fn new(
Expand Down Expand Up @@ -102,6 +96,7 @@ impl CryptoEntityClient {
mod tests {
use crate::crypto::crypto_facade::{MockCryptoFacade, ResolvedSessionKey};
use crate::crypto::key::GenericAesKey;
use crate::crypto::randomizer_facade::RandomizerFacade;
use crate::crypto::{aes::Iv, Aes256Key};
use crate::crypto_entity_client::CryptoEntityClient;
use crate::date::DateTime;
Expand Down Expand Up @@ -173,7 +168,10 @@ mod tests {
let type_model_provider = Arc::new(init_type_model_provider());

// Use the real `EntityFacade` as it contains the actual decryption logic
let entity_facade = EntityFacadeImpl::new(Arc::clone(&type_model_provider));
let entity_facade = EntityFacadeImpl::new(
Arc::clone(&type_model_provider),
RandomizerFacade::from_core(rand_core::OsRng),
);

let crypto_entity_client = CryptoEntityClient::new(
Arc::new(mock_entity_client),
Expand Down
Loading

0 comments on commit 6221be6

Please sign in to comment.