Skip to content

Commit

Permalink
Get std out of handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Apr 19, 2024
1 parent e4e7699 commit f08987f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const TAG_BYTES: usize = 16;
const LENGTH_BYTES: usize = 3;
/// Value for decoy flag.
const DECOY: u8 = 128;
/// Version content is always empty for the current version of the protocol.
const VERSION_CONTENT: [u8; 0] = [];

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Error {
Expand Down Expand Up @@ -700,12 +702,15 @@ impl<'a> Handshake<'a> {

let mut packet_handler = PacketHandler::new(materials, self.role.clone());

// TODO: Support decoy packets.
// TODO: Support sending decoy packets before the version packet.

// Empty vec is signaling version.
let version_packet = packet_handler.prepare_v2_packet(Vec::new(), self.garbage, false)?;

response[16..16 + version_packet.len()].copy_from_slice(&version_packet);
packet_handler.packet_writer.prepare_packet(
&VERSION_CONTENT,
self.garbage,
&mut response[16..16 + LENGTH_BYTES + DECOY_BYTES + TAG_BYTES],
false,
)?;

self.packet_handler = Some(packet_handler);

Expand Down

0 comments on commit f08987f

Please sign in to comment.