Exemplo n.º 1
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);
        }