diff --git a/src/sock/enc.rs b/src/sock/enc.rs index 8e056ab..07ccc4d 100644 --- a/src/sock/enc.rs +++ b/src/sock/enc.rs @@ -461,7 +461,8 @@ impl ESock } } -//XXXXXXX: This isn't working. The first write to the socket succeeds. Any subsequent writes/reads produce garbage. Why? +//XXX: For some reason, non-exact reads + writes cause garbage to be produced on the receiving end? +// Is this fixable? Why does it disjoint? I have no idea... This is supposed to be a stream cipher, right? Why does positioning matter? Have I misunderstood how it workd? Eh... impl AsyncWrite for ESock where W: AsyncWrite @@ -717,7 +718,7 @@ mod tests // The duplex buffer size here is smaller than an RSA ciphertext block. So, writing the session key must be buffered with a buffer size this small (should return Pending at least once.) // Using a low buffer size to make sure the test passes even when the entire buffer cannot be written at once. - let (mut tx, mut rx) = gen_duplex_esock(256).wrap_err(eyre!("Failed to weave socks"))?; + let (mut tx, mut rx) = gen_duplex_esock(16).wrap_err(eyre!("Failed to weave socks"))?; let writer = tokio::spawn(async move { use tokio::prelude::*; @@ -728,9 +729,8 @@ mod tests tx.set_encrypted_write(true).await?; assert_eq!((true, false), tx.is_encrypted()); - tx.write_all(&VALUE[0..2]).await?; - tx.write_all(&VALUE[2..6]).await?; - tx.write_all(&VALUE[6..]).await?; + tx.write_all(VALUE).await?; + tx.write_all(VALUE).await?; // Check resp tx.set_encrypted_read(true).await?; @@ -757,6 +757,11 @@ mod tests let mut val = vec![0u8; VALUE.len()]; rx.read_exact(&mut val[..]).await?; + + let mut val2 = vec![0u8; VALUE.len()]; + rx.read_exact(&mut val2[..]).await?; + + assert_eq!(val, val2); // Send resp rx.set_encrypted_write(true).await?;