microsoft / referencesource

Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
https://referencesource.microsoft.com/
MIT License
3.16k stars 1.27k forks source link

Async way for computing Hash #98

Closed mgardi85 closed 5 years ago

mgardi85 commented 5 years ago

Within System.Security.Cryptography.HashAlgorithm we have a compute hash overload which takes stream as parameter input and then reads through the stream to compute the hash.

Since the reading may involve IO , can a new member "ComputeHashAsync" be introduced which would read assynchronously .

This would be helpful in freeing up threads .

we can have something like public Task async<byte[]> ComputeHashAsync(Stream inputStream) { if (m_bDisposed) throw new ObjectDisposedException(null); byte[] buffer = new byte[4096]; int bytesRead; do { bytesRead = await inputStream.ReadAsync(buffer, 0, 4096); if (bytesRead > 0) { HashCore(buffer, 0, bytesRead); } } while (bytesRead > 0); HashValue = HashFinal(); byte[] Tmp = (byte[]) HashValue.Clone(); Initialize(); return(Tmp); } https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/security/cryptography/hashalgorithm.cs

svick commented 5 years ago

First of all, this is not the right place to request features for .Net Framework.

Second, I don't think this kind of changes are being done to .Net Framework anymore. Your best bet is to focus on .Net Core going forwards. And if you want to request a new API for .Net Core, the right place is the corefx repository.

mgardi85 commented 5 years ago

thanks for the reply. will follow up in corefx repository