Skip to content

Commit

Permalink
Remove unnecessary cloning and zeroizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Dec 2, 2024
1 parent bcc4bc7 commit de00110
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/ciphernode/cipher/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> Result<Vec<u8>> {
encrypt_data(&self.key, data)
}
Expand Down
4 changes: 1 addition & 3 deletions packages/ciphernode/net/src/network_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}
Expand Down

0 comments on commit de00110

Please sign in to comment.