let mut reader = BufReader::new(&stream);
// Read server's public key
reader.read_until(b'\n', &mut buffer)
This is clearly wrong - sever public key is send as stream of arbitrary bytes. What if it will contain b'\n' - for this example read_to_end should be enough and then we do not need buffered reader.
Share this highlighthttp://learning.oreilly.com/a/network-programming-with/19030757/