Clean up usage of ArrayPool in the Cryptography assemblies
The primary motivator of this change is to prepare for moving cryptography from
the public, shared ArrayPool instance to a private pool (or pools), just as a defense
in depth strategy. Since only the shared ArrayPool instance has GC cooperation
the change to a private pool is not happening at this time.
What this change does provide:
* Every ArrayPool.Rent was identified as being private to the assembly or shared
out. If the array gets shared out, it is not appropriate to use a private pool.
* CryptoPool clears returned arrays by default. Instead of an optional bool for
clearing it has an optional length to clear (from index 0).
* Some rents were removed altogether, via a couple strategies:
* Opportunistic stackalloc
* Add a SpanAction-based AsnWriter.WriteBitString overload to avoid the
pattern of rent-write-call-copy (instead do request-write-done).
* Add AsnWriter.ValueEquals to prevent rent-encode-compare.
* At least one Rent with no Return was found and fixed.
* Fixed several Rent-growth strategies that could double-Return on exceptions.
* Changed Rfc2898DeriveBytes to just use the one field array instead of a
lot of rent-write-copy-to-the-field.
* Moves some Return calls out of finally blocks in Async methods to avoid a
Return-while-in-use path with Task composition when one Task gets aborted
and another is still running.
Commit migrated from https://github.com/dotnet/corefx/commit/
64609475281f2be05a0b9ca5b7bbdaf43b12dc55