From 52f2104c783cce6f8d03d881f7529aab4f0d602b Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Fri, 2 Jun 2017 08:59:50 -0700 Subject: [PATCH] React to Base64 API changes --- .../Internal/Formatters/MessageFormatUtils.cs | 5 +++-- .../Internal/Formatters/ServerSentEventsMessageFormatter.cs | 2 +- .../Internal/Formatters/TextMessageFormatter.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/MessageFormatUtils.cs b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/MessageFormatUtils.cs index 2d2c25327e..1b317a0d6a 100644 --- a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/MessageFormatUtils.cs +++ b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/MessageFormatUtils.cs @@ -3,6 +3,7 @@ using System; using System.Binary.Base64; +using System.Buffers; namespace Microsoft.AspNetCore.Sockets.Internal.Formatters { @@ -13,11 +14,11 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters if (inputPayload.Length > 0) { // Determine the output size - var decodedLength = Base64Encoder.ComputeDecodedLength(inputPayload); + var decodedLength = Base64Decoder.ComputeDecodedLength(inputPayload); // Allocate a new buffer to decode to var decodeBuffer = new byte[decodedLength]; - if (!Base64Encoder.TryDecode(inputPayload, decodeBuffer, out _, out var _)) + if (Base64.Decoder.Transform(inputPayload, decodeBuffer, out _, out var _) != TransformationStatus.Done) { throw new FormatException("Invalid Base64 payload"); } diff --git a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/ServerSentEventsMessageFormatter.cs b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/ServerSentEventsMessageFormatter.cs index 29fdf3d669..266bf217ac 100644 --- a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/ServerSentEventsMessageFormatter.cs +++ b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/ServerSentEventsMessageFormatter.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters { // TODO: Base64 writer that works with IOutput would be amazing! var arr = new byte[Base64Encoder.ComputeEncodedLength(payload.Length)]; - Base64Encoder.TryEncode(payload, arr, out _, out _); + Base64.Encoder.Transform(payload, arr, out _, out _); return TryWriteLine(arr, output); } else diff --git a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/TextMessageFormatter.cs b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/TextMessageFormatter.cs index 56d9897dc9..f05a52303b 100644 --- a/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/TextMessageFormatter.cs +++ b/src/Microsoft.AspNetCore.Sockets.Common/Internal/Formatters/TextMessageFormatter.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters { // TODO: Base64 writer that works with IOutput would be amazing! var arr = new byte[Base64Encoder.ComputeEncodedLength(message.Payload.Length)]; - Base64Encoder.TryEncode(message.Payload, arr, out _, out _); + Base64.Encoder.Transform(message.Payload, arr, out _, out _); return output.TryWrite(arr); } else