예제 #1
0
        public void FirstWriteSendsNonce()
        {
            var psk = new PreSharedKey().Generate();

            var insecure = new MemoryStream();
            var secure   = new Psk1Stream(insecure, psk);

            secure.WriteByte(0x10);
            Assert.AreEqual(24 + 1, insecure.Length);

            insecure = new MemoryStream();
            secure   = new Psk1Stream(insecure, psk);
            secure.Write(new byte[10], 0, 10);
            Assert.AreEqual(24 + 10, insecure.Length);

            insecure = new MemoryStream();
            secure   = new Psk1Stream(insecure, psk);
            secure.WriteAsync(new byte[12], 0, 12).Wait();
            Assert.AreEqual(24 + 12, insecure.Length);
        }
예제 #2
0
        public void Roundtrip()
        {
            var psk    = new PreSharedKey().Generate();
            var plain  = new byte[] { 1, 2, 3 };
            var plain1 = new byte[3];
            var plain2 = new byte[3];

            var insecure = new MemoryStream();
            var secure   = new Psk1Stream(insecure, psk);

            secure.Write(plain, 0, plain.Length);
            secure.Flush();

            insecure.Position = 0;
            secure            = new Psk1Stream(insecure, psk);
            secure.Read(plain1, 0, plain1.Length);
            CollectionAssert.AreEqual(plain, plain1);

            insecure.Position = 0;
            secure            = new Psk1Stream(insecure, psk);
            secure.ReadAsync(plain2, 0, plain2.Length).Wait();
            CollectionAssert.AreEqual(plain, plain2);
        }