public void TestSimpleDownload()
        {
            byte[] src = new byte[ushort.MaxValue];
            MemoryStream dest = new MemoryStream();
            new Random().NextBytes(src);

            SecureTransfer.Server server = new SecureTransfer.Server(ServerKey, ClientKey.PublicKey, new RegistryStorage());
            server.MaxOutboundFileChunk = 1000;
            server.DownloadBytes +=
                (o, e) =>
                {
                    using (MemoryStream ms = new MemoryStream(e.ReadLength))
                    {
                        ms.Write(src, (int)e.ReadOffset, e.ReadLength);
                        e.SetBytes(src.Length, ms.ToArray());
                    }
                };

            SecureTransfer.Client client = new SecureTransfer.Client(ClientKey, ServerKey.PublicKey,
                (id, name, stream) => server.Receive(stream));

            client.Download("bla", dest);
            Assert.AreEqual(Hash.SHA256(src), Hash.SHA256(dest.ToArray()));
        }
        public void TestDownloadOneChunk()
        {
            byte[] src = new byte[1024];
            MemoryStream dest = new MemoryStream();
            new Random().NextBytes(src);
            Hash expectHash = Hash.SHA256(src);

            SecureTransfer.Server server = new SecureTransfer.Server(ServerKey, ClientKey.PublicKey, new RegistryStorage());
            server.MaxOutboundFileChunk = src.Length;
            server.DownloadBytes +=
                (o, e) =>
                {
                    if (e.ReadLength == 0)
                        e.SetBytes(src.Length, null);
                    else
                    {
                        e.SetBytes(src.Length, src);
                        src = null;
                    }
                };

            SecureTransfer.Client client = new SecureTransfer.Client(ClientKey, ServerKey.PublicKey,
                (id, name, stream) => server.Receive(stream));

            client.Download("bla", dest);
            Assert.IsNull(src);
            Assert.AreEqual(expectHash, Hash.SHA256(dest.ToArray()));
        }
        public void TestDownloadFails()
        {
            SecureTransfer.Server server = new SecureTransfer.Server(ServerKey, ClientKey.PublicKey, new RegistryStorage());
            server.MaxOutboundFileChunk = 1000;
            server.DownloadBytes += (o, e) => e.SetBytes(ushort.MaxValue, null);

            SecureTransfer.Client client = new SecureTransfer.Client(ClientKey, ServerKey.PublicKey,
                (id, name, stream) => server.Receive(stream));

            MemoryStream dest = new MemoryStream();
            try
            {
                client.Download("bla", dest);
                Assert.Fail();
            }
            catch(InvalidDataException) { }
        }