protected override void HandleHandshakeRequest() { // For incoming connection, the peer would send the public key to generate a shared secret. var networkStream = NetworkStream; var packet = Packet.Parser.ParseDelimitedFrom(networkStream); if (packet.PacketType != PacketType.Handshake) { throw new Exception("Invalid packet type."); } KeepAliveDuration = packet.PacketKeepAliveDuration; var handshakePacket = PacketUtility.DeserializePacketData(packet, HandshakePacket.Parser); if (handshakePacket.HandshakeType == HandshakeType.CipherText) { throw new Exception("Invalid handshake type."); } using var kem = new KeyEncapsulationMechanism(handshakePacket.KeyEncapsulationMechanismType switch { KeyEncapsulationMechanismType.NtruHps4096821 => "NTRU-HPS-4096-821", var _ => throw new ArgumentOutOfRangeException() });