我想实现一个 IInputStream ,它委托给另一个 IInputStream 并在将读取的数据返回给用户之前对其进行处理,如下所示:
using System;
using Windows.Storage.Streams;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
namespace Core.Crypto {
public class RC4InputStream : IInputStream {
public RC4InputStream(IInputStream stream, byte[] readKey) {
_stream = stream;
_cipher = new RC4Engine();
_cipher.Init(false, new KeyParameter(readKey));
}
public Windows.Foundation.IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
{
var op = _stream.ReadAsync(buffer, count, options);
// Somehow magically hook up something so that I can call _cipher.ProcessBytes(...)
return op;
}
private readonly IInputStream _stream;
private readonly IStreamCipher _cipher;
}
}
我有两个不同的问题,我无法通过搜索浩瀚的互联网来回答:
- 在委派的 ReadAsync() 之后链接另一个操作以运行的最佳方法是什么(我可以使用“等待”,也可以使用 AsyncInfo 创建一个新的 IAsyncOperation,但我不知道如何连接进度报告器等)
- 如何访问“IBuffer”背后的数据?