React to Base64 API changes

This commit is contained in:
BrennanConroy 2017-06-02 08:59:50 -07:00 committed by Kiran Challa
parent 12fb3de3a6
commit 52f2104c78
3 changed files with 5 additions and 4 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Binary.Base64; using System.Binary.Base64;
using System.Buffers;
namespace Microsoft.AspNetCore.Sockets.Internal.Formatters namespace Microsoft.AspNetCore.Sockets.Internal.Formatters
{ {
@ -13,11 +14,11 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters
if (inputPayload.Length > 0) if (inputPayload.Length > 0)
{ {
// Determine the output size // Determine the output size
var decodedLength = Base64Encoder.ComputeDecodedLength(inputPayload); var decodedLength = Base64Decoder.ComputeDecodedLength(inputPayload);
// Allocate a new buffer to decode to // Allocate a new buffer to decode to
var decodeBuffer = new byte[decodedLength]; 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"); throw new FormatException("Invalid Base64 payload");
} }

View File

@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters
{ {
// TODO: Base64 writer that works with IOutput would be amazing! // TODO: Base64 writer that works with IOutput would be amazing!
var arr = new byte[Base64Encoder.ComputeEncodedLength(payload.Length)]; 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); return TryWriteLine(arr, output);
} }
else else

View File

@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Formatters
{ {
// TODO: Base64 writer that works with IOutput would be amazing! // TODO: Base64 writer that works with IOutput would be amazing!
var arr = new byte[Base64Encoder.ComputeEncodedLength(message.Payload.Length)]; 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); return output.TryWrite(arr);
} }
else else