From de00110aafc4c15298a3d9a3797ecf15dcb9865c Mon Sep 17 00:00:00 2001 From: ryardley Date: Mon, 2 Dec 2024 15:02:22 +0700 Subject: [PATCH] Remove unnecessary cloning and zeroizing --- packages/ciphernode/cipher/src/cipher.rs | 1 + packages/ciphernode/net/src/network_manager.rs | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ciphernode/cipher/src/cipher.rs b/packages/ciphernode/cipher/src/cipher.rs index 3321271f..ded90491 100644 --- a/packages/ciphernode/cipher/src/cipher.rs +++ b/packages/ciphernode/cipher/src/cipher.rs @@ -132,6 +132,7 @@ impl Cipher { Ok(Self::new(FilePasswordManager::new(config.key_file())).await?) } + /// Encrypt the given data and zeroize the data after encryption pub fn encrypt_data(&self, data: &mut Vec) -> Result> { encrypt_data(&self.key, data) } diff --git a/packages/ciphernode/net/src/network_manager.rs b/packages/ciphernode/net/src/network_manager.rs index 24046819..00f3f45f 100644 --- a/packages/ciphernode/net/src/network_manager.rs +++ b/packages/ciphernode/net/src/network_manager.rs @@ -91,14 +91,12 @@ impl NetworkManager { bytes }; - // We need to clone here to ensure bytes are not zeroized locally as this leads to a test failure. - let ed25519_keypair = ed25519::Keypair::try_from_bytes(&mut bytes.clone())?; + let ed25519_keypair = ed25519::Keypair::try_from_bytes(&mut bytes)?; let keypair: libp2p::identity::Keypair = ed25519_keypair.try_into()?; let mut peer = NetworkPeer::new(&keypair, peers, None, "tmp-enclave-gossip-topic")?; let rx = peer.rx().ok_or(anyhow!("Peer rx already taken"))?; let p2p_addr = NetworkManager::setup(bus, peer.tx(), rx); let handle = tokio::spawn(async move { Ok(peer.start().await?) }); - bytes.zeroize(); Ok((p2p_addr, handle, keypair.public().to_peer_id().to_string())) } }