public void CryptoStreamWithEmptyFinalBlockViaRead()
    {
        var transform = new MockCryptoTransform(5);
        var target    = new ErraticReaderStream(new MemoryStream(Encoding.UTF8.GetBytes("BCDEFGHJKLMNOPQ")));

        using (Stream? stream = this.CreateCryptoStream(target, transform, CryptoStreamMode.Read))
        {
            byte[] buffer = new byte[100];
            Assert.Equal(4, stream.Read(buffer, 0, 4));
            Assert.Equal("-BCD", Encoding.UTF8.GetString(buffer, 0, 4));
            Assert.Equal(5, stream.Read(buffer, 4, 5));
            Assert.Equal("EF-GH", Encoding.UTF8.GetString(buffer, 4, 5));
            Assert.Equal(11, stream.Read(buffer, 9, 12));
            Assert.Equal("JKL-MNOPQ_Z", Encoding.UTF8.GetString(buffer, 9, 11));
            Assert.Equal(0, stream.Read(buffer, 0, 10)); // EOF

            string expected = "-BCDEF-GHJKL-MNOPQ_Z";
            Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, expected.Length));
        }
    }
示例#2
0
    public void CryptoStreamWithEmptyFinalBlockViaRead()
    {
        var transform = new MockCryptoTransform(5);
        var target = new ErraticReaderStream(new MemoryStream(Encoding.UTF8.GetBytes("BCDEFGHJKLMNOPQ")));
        using (var stream = this.CreateCryptoStream(target, transform, CryptoStreamMode.Read))
        {
            byte[] buffer = new byte[100];
            Assert.Equal(4, stream.Read(buffer, 0, 4));
            Assert.Equal("-BCD", Encoding.UTF8.GetString(buffer, 0, 4));
            Assert.Equal(5, stream.Read(buffer, 4, 5));
            Assert.Equal("EF-GH", Encoding.UTF8.GetString(buffer, 4, 5));
            Assert.Equal(11, stream.Read(buffer, 9, 12));
            Assert.Equal("JKL-MNOPQ_Z", Encoding.UTF8.GetString(buffer, 9, 11));
            Assert.Equal(0, stream.Read(buffer, 0, 10)); // EOF

            string expected = "-BCDEF-GHJKL-MNOPQ_Z";
            Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, expected.Length));
        }
    }