コード例 #1
0
        private static async Task <MemoryStream> InternalGetDecryptionStreamAsync(Stream input, IMS2SizeHeader size, IBufferedCipher cipher, bool zlibCompressed)
        {
            using var cs = new CipherStream(input, cipher, null);
            byte[] bytes = new byte[size.Size];

            int readBytes;

            if (zlibCompressed)
            {
                using var z = new ZlibStream(cs, CompressionMode.Decompress, true);
                readBytes   = await z.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            }
            else
            {
                readBytes = await cs.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            }

            if (readBytes != size.Size)
            {
                throw new ArgumentException("Size bytes from input do not match with header size.", nameof(input));
            }

            return(new MemoryStream(bytes));
        }