次のように、別の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;
}
}
私はインターネットの広大さを検索することによって答えることができなかった2つの異なる問題を抱えています:
- 委任されたReadAsync()の後に実行する別の操作をチェーンする最良の方法は何ですか(「await」を使用し、AsyncInfoを使用して新しいIAsyncOperationを作成することもできますが、progress reporterなどを接続する方法がわかりません)
- 「IBuffer」の背後にあるデータにアクセスするにはどうすればよいですか?