Example #1
0
        public async Task EnsureDisposeWorks()
        {
            FieldInfo f;

            byte[] key = EncryptionHelpers.CreateEncryptionKey();
            using (MemoryStream ms = new MemoryStream())
            {
                CryptographicStream s = await EncryptionHelpers.GetEncryptionStreamAsync(key, ms);

                f = s.GetType().GetField("_underlyingStream", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.NotNull(f.GetValue(s));
                s.Dispose();
                Assert.Null(f.GetValue(s));
            }
        }
        /// <summary>
        /// Opens a read-only stream to the given blob path.
        /// </summary>
        public override async Task <Stream?> GetBlobReadStreamAsync(string path)
        {
            Stream?underlying = await base.GetBlobReadStreamAsync(path);

            if (underlying == null)
            {
                return(null);
            }
            else
            {
                Stream seekable = new MemoryStream();
                using (CryptographicStream s = await EncryptionHelpers.GetDecryptionStreamAsync(_encryptionKey, underlying))
                {
                    await s.CopyToAsync(seekable);

                    seekable.Seek(0, SeekOrigin.Begin);
                }
                return(seekable);
            }
        }