-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Enable ToBase64Transform.CanTransformMultipleBlocks #55055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsFixes #55029
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using System;
using BenchmarkDotNet.Diagnosers;
using Perfolizer.Horology;
using BenchmarkDotNet.Columns;
using System.Globalization;
using BenchmarkDotNet.Reports;
using System.Security.Cryptography;
using System.IO;
[MemoryDiagnoser]
public class Program
{
public static void Main(string[] args) =>
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args,
DefaultConfig.Instance.WithSummaryStyle(new SummaryStyle(CultureInfo.InvariantCulture,
printUnitsInHeader: false, sizeUnit: SizeUnit.B, timeUnit: TimeUnit.Nanosecond, printZeroValuesInContent: true)));
private byte[] _data = RandomNumberGenerator.GetBytes(10_000_000);
private MemoryStream _destination = new MemoryStream();
[Benchmark]
public void Encode()
{
_destination.Position = 0;
using (var toBase64 = new ToBase64Transform())
using (var stream = new CryptoStream(_destination, toBase64, CryptoStreamMode.Write, leaveOpen: true))
{
Span<byte> remaining = _data;
while (!remaining.IsEmpty)
{
Span<byte> toWrite = remaining.Slice(0, Math.Min(4096, remaining.Length));
stream.Write(toWrite);
remaining = remaining.Slice(toWrite.Length);
}
}
}
}
|
...s/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Base64Transforms.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Base64Transforms.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Base64Transforms.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Base64TransformsTests.cs
Outdated
Show resolved
Hide resolved
|
I'm realizing now I misunderstood the contract, and the implementation needs to be much more complex, to handle cases where more input is provided than can fit into the output space provided... I was only encoding what would fit, but it appears the contract actually requires the remaining input data to be saved off for later. |
|
Turns out the implementation doesn't need to be more complex as it can make simplifying assumptions about the inputs, ala what UniversalCryptoTransform does. And since this never previously supported anything other than one input block that entirely fit into the output, this won't be a breaking change. I'll fix up the input validation accordingly. |
963e545 to
63f7e10
Compare
Fixes #55029