From 60e785b2380b25269ecb21921226bf98b7af8221 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 20 Jun 2024 23:08:33 -0700 Subject: [PATCH] Apply feedbacks --- .../src/System/Buffers/Text/Base64Decoder.cs | 5 +- .../src/System/Buffers/Text/Base64Encoder.cs | 7 +- .../Text/Base64Helper/Base64DecoderHelper.cs | 25 +++---- .../Text/Base64Helper/Base64EncoderHelper.cs | 20 +++--- .../Buffers/Text/Base64Helper/Base64Helper.cs | 6 +- .../Base64Helper/Base64ValidatorHelper.cs | 21 +++--- .../Text/Base64Url/Base64UrlDecoder.cs | 71 +++++++++---------- .../Text/Base64Url/Base64UrlEncoder.cs | 49 ++++++------- .../Text/Base64Url/Base64UrlValidator.cs | 28 +++----- .../System/Buffers/Text/Base64Validator.cs | 10 +-- 10 files changed, 107 insertions(+), 135 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs index 9c2e6a793a90aa..dfd8a08063249e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using static System.Buffers.Text.Base64Helper; namespace System.Buffers.Text { @@ -29,7 +30,7 @@ public static partial class Base64 /// or if the input is incomplete (i.e. not a multiple of 4) and is . /// public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span bytes, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) => - Base64Helper.DecodeFrom(Base64Helper.s_base64ByteDecoder, utf8, bytes, out bytesConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); + DecodeFrom(default(Base64DecoderByte), utf8, bytes, out bytesConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); /// /// Returns the maximum length (in bytes) of the result if you were to decode base 64 encoded text within a byte span of size "length". @@ -61,6 +62,6 @@ public static int GetMaxDecodedFromUtf8Length(int length) /// hence can only be called once with all the data in the buffer. /// public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int bytesWritten) => - Base64Helper.DecodeFromUtf8InPlace(Base64Helper.s_base64ByteDecoder, buffer, out bytesWritten, ignoreWhiteSpace: true); + Base64Helper.DecodeFromUtf8InPlace(default(Base64DecoderByte), buffer, out bytesWritten, ignoreWhiteSpace: true); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index 13c903f06525e5..9583d685516375 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using static System.Buffers.Text.Base64Helper; namespace System.Buffers.Text { @@ -32,7 +33,7 @@ public static partial class Base64 /// It does not return InvalidData since that is not possible for base64 encoding. /// public static OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span utf8, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) => - Base64Helper.EncodeTo(Base64Helper.s_base64ByteEncoder, bytes, utf8, out bytesConsumed, out bytesWritten, isFinalBlock); + EncodeTo(default(Base64EncoderByte), bytes, utf8, out bytesConsumed, out bytesWritten, isFinalBlock); /// /// Returns the maximum length (in bytes) of the result if you were to encode binary data within a byte span of size "length". @@ -43,7 +44,7 @@ public static OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetMaxEncodedToUtf8Length(int length) { - ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)length, Base64Helper.MaximumEncodeLength); + ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)length, MaximumEncodeLength); return ((length + 2) / 3) * 4; } @@ -64,6 +65,6 @@ public static int GetMaxEncodedToUtf8Length(int length) /// It does not return InvalidData since that is not possible for base 64 encoding. /// public static OperationStatus EncodeToUtf8InPlace(Span buffer, int dataLength, out int bytesWritten) => - Base64Helper.EncodeToUtf8InPlace(Base64Helper.s_base64ByteEncoder, buffer, dataLength, out bytesWritten); + Base64Helper.EncodeToUtf8InPlace(default(Base64EncoderByte), buffer, dataLength, out bytesWritten); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs index d5d9acdff968d4..628be863e38c66 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if NETCOREAPP +#if NET using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics; @@ -14,10 +14,6 @@ namespace System.Buffers.Text { internal static partial class Base64Helper { -#pragma warning disable CA1805 // Member 's_base64ByteDecoder' is explicitly initialized to its default value - internal static Base64DecoderByte s_base64ByteDecoder = default; -#pragma warning restore CA1805 - internal static unsafe OperationStatus DecodeFrom(TBase64Decoder decoder, ReadOnlySpan source, Span bytes, out int bytesConsumed, out int bytesWritten, bool isFinalBlock, bool ignoreWhiteSpace) where TBase64Decoder : IBase64Decoder @@ -50,7 +46,7 @@ internal static unsafe OperationStatus DecodeFrom(TBase64Deco T* srcEnd = srcBytes + (uint)srcLength; T* srcMax = srcBytes + (uint)maxSrcLength; -#if NETCOREAPP +#if NET if (maxSrcLength >= 24) { T* end = srcMax - 88; @@ -112,7 +108,7 @@ internal static unsafe OperationStatus DecodeFrom(TBase64Deco // This should never overflow since destLength here is less than int.MaxValue / 4 * 3 (i.e. 1610612733) // Therefore, (destLength / 3) * 4 will always be less than 2147483641 Debug.Assert(destLength < (int.MaxValue / 4 * 3)); -#if NETCOREAPP +#if NET (maxSrcLength, int remainder) = int.DivRem(destLength, 3); maxSrcLength *= 4; #else @@ -643,13 +639,13 @@ private static OperationStatus DecodeWithWhiteSpaceFromUtf8InPlace(TBase64Decoder decoder, ref T* srcBytes, ref byte* destBytes, T* srcEnd, int sourceLength, int destLength, T* srcStart, byte* destStart) - where TBase64Decoder : IBase64Decoder - where T : unmanaged + where TBase64Decoder : IBase64Decoder + where T : unmanaged { // Reference for VBMI implementation : https://github.com/WojciechMula/base64simd/tree/master/decode // If we have AVX512 support, pick off 64 bytes at a time for as long as we can, @@ -1243,12 +1239,7 @@ internal static bool IsWhiteSpace(int value) public uint AdvSimdLutTwo3Uint1 => 0x1B1AFFFF; - public int GetMaxDecodedLength(int utf8Length) => -#if NETCOREAPP - Base64.GetMaxDecodedFromUtf8Length(utf8Length); -#else - 0; -#endif + public int GetMaxDecodedLength(int utf8Length) => Base64.GetMaxDecodedFromUtf8Length(utf8Length); public bool IsInvalidLength(int bufferLength) => bufferLength % 4 != 0; // only decode input if it is a multiple of 4 @@ -1256,7 +1247,7 @@ public int GetMaxDecodedLength(int utf8Length) => public int SrcLength(bool _, int utf8Length) => utf8Length & ~0x3; // only decode input up to the closest multiple of 4. -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] [CompExactlyDependsOn(typeof(Ssse3))] diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64EncoderHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64EncoderHelper.cs index dd55f46b560af0..6e888bc77f7c1f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64EncoderHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64EncoderHelper.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if NETCOREAPP +#if NET using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; @@ -13,10 +13,6 @@ namespace System.Buffers.Text { internal static partial class Base64Helper { -#pragma warning disable CA1805 // Member 's_base64ByteEncoder' is explicitly initialized to its default value - internal static Base64EncoderByte s_base64ByteEncoder = default; -#pragma warning restore CA1805 - internal static unsafe OperationStatus EncodeTo(TBase64Encoder encoder, ReadOnlySpan source, Span destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) where TBase64Encoder : IBase64Encoder @@ -41,7 +37,7 @@ internal static unsafe OperationStatus EncodeTo(TBase64Encode byte* srcEnd = srcBytes + (uint)srcLength; byte* srcMax = srcBytes + (uint)maxSrcLength; -#if NETCOREAPP +#if NET if (maxSrcLength >= 16) { byte* end = srcMax - 64; @@ -132,13 +128,13 @@ internal static unsafe OperationStatus EncodeTo(TBase64Encode } } -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(Avx512BW))] [CompExactlyDependsOn(typeof(Avx512Vbmi))] private static unsafe void Avx512Encode(TBase64Encoder encoder, ref byte* srcBytes, ref T* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, T* destStart) - where TBase64Encoder : IBase64Encoder - where T : unmanaged + where TBase64Encoder : IBase64Encoder + where T : unmanaged { // Reference for VBMI implementation : https://github.com/WojciechMula/base64simd/tree/master/encode // If we have AVX512 support, pick off 48 bytes at a time for as long as we can. @@ -664,7 +660,7 @@ private static unsafe uint Encode(byte* threeBytes, ref byte encodingMap) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetMaxSrcLength(int srcLength, int destLength) => -#if NETCOREAPP +#if NET srcLength <= MaximumEncodeLength && destLength >= Base64.GetMaxEncodedToUtf8Length(srcLength) ? srcLength : (destLength >> 2) * 3; #else @@ -674,7 +670,7 @@ public int GetMaxSrcLength(int srcLength, int destLength) => public uint GetInPlaceDestinationLength(int encodedLength, int _) => (uint)(encodedLength - 4); public int GetMaxEncodedLength(int srcLength) => -#if NETCOREAPP +#if NET Base64.GetMaxEncodedToUtf8Length(srcLength); #else 0; @@ -734,7 +730,7 @@ public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, byte* dest, ref byt } } -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe void StoreVector512ToDestination(byte* dest, byte* destStart, int destLength, Vector512 str) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs index a87c32df2bf2e5..b86600c74db27a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; -#if NETCOREAPP +#if NET using System.Runtime.Intrinsics; #endif @@ -82,7 +82,7 @@ internal interface IBase64Encoder where T : unmanaged unsafe void EncodeThreeAndWrite(byte* threeBytes, T* destination, ref byte encodingMap); int IncrementPadTwo { get; } int IncrementPadOne { get; } -#if NETCOREAPP +#if NET unsafe void StoreVector512ToDestination(T* dest, T* destStart, int destLength, Vector512 str); unsafe void StoreVector256ToDestination(T* dest, T* destStart, int destLength, Vector256 str); unsafe void StoreVector128ToDestination(T* dest, T* destStart, int destLength, Vector128 str); @@ -109,7 +109,7 @@ internal interface IBase64Decoder where T : unmanaged int GetMaxDecodedLength(int sourceLength); bool IsInvalidLength(int bufferLength); bool IsValidPadding(uint padChar); -#if NETCOREAPP +#if NET bool TryDecode128Core( Vector128 str, Vector128 hiNibbles, diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64ValidatorHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64ValidatorHelper.cs index 2549710a4f7277..d857bb3d0eca08 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64ValidatorHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64ValidatorHelper.cs @@ -7,11 +7,6 @@ namespace System.Buffers.Text { internal static partial class Base64Helper { -#pragma warning disable CA1805 // Member 's_base64ByteEncoder' is explicitly initialized to its default value - internal static Base64ByteValidatable s_base64ByteValidatable = default; - internal static Base64CharValidatable s_base64CharValidatable = default; -#pragma warning restore CA1805 - internal static bool IsValid(TBase64Validatable validatable, ReadOnlySpan base64Text, out int decodedLength) where TBase64Validatable : IBase64Validatable { @@ -19,7 +14,7 @@ internal static bool IsValid(TBase64Validatable validatab if (!base64Text.IsEmpty) { -#if NETCOREAPP +#if NET while (true) { @@ -128,7 +123,7 @@ internal static bool IsValid(TBase64Validatable validatab internal interface IBase64Validatable { -#if NETCOREAPP +#if NET int IndexOfAnyExcept(ReadOnlySpan span); #else int DecodeValue(T value); @@ -140,7 +135,7 @@ internal interface IBase64Validatable internal readonly struct Base64CharValidatable : IBase64Validatable { -#if NETCOREAPP +#if NET private static readonly SearchValues s_validBase64Chars = SearchValues.Create("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); public int IndexOfAnyExcept(ReadOnlySpan span) => span.IndexOfAnyExcept(s_validBase64Chars); @@ -153,24 +148,24 @@ public int DecodeValue(char value) return -2; } - return s_base64ByteDecoder.DecodingMap[value]; + return default(Base64DecoderByte).DecodingMap[value]; } #endif public bool IsWhiteSpace(char value) => Base64Helper.IsWhiteSpace(value); public bool IsEncodingPad(char value) => value == EncodingPad; public bool ValidateAndDecodeLength(int length, int paddingCount, out int decodedLength) => - s_base64ByteValidatable.ValidateAndDecodeLength(length, paddingCount, out decodedLength); + default(Base64ByteValidatable).ValidateAndDecodeLength(length, paddingCount, out decodedLength); } internal readonly struct Base64ByteValidatable : IBase64Validatable { -#if NETCOREAPP - private static readonly SearchValues s_validBase64Chars = SearchValues.Create(s_base64ByteEncoder.EncodingMap); +#if NET + private static readonly SearchValues s_validBase64Chars = SearchValues.Create(default(Base64EncoderByte).EncodingMap); public int IndexOfAnyExcept(ReadOnlySpan span) => span.IndexOfAnyExcept(s_validBase64Chars); #else public int DecodeValue(byte value) => - s_base64ByteDecoder.DecodingMap[value]; + default(Base64DecoderByte).DecodingMap[value]; #endif public bool IsWhiteSpace(byte value) => Base64Helper.IsWhiteSpace(value); public bool IsEncodingPad(byte value) => value == EncodingPad; diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs index e3335042547a7c..2c47be6a76602b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs @@ -4,12 +4,13 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if NETCOREAPP +#if NET using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; #endif using System.Text; +using static System.Buffers.Text.Base64Helper; namespace System.Buffers.Text { @@ -18,10 +19,6 @@ namespace System.Buffers.Text public static partial class Base64Url { private const int MaxStackallocThreshold = 256; -#pragma warning disable CA1805 // Member 's_base64UrlByteDecoder' is explicitly initialized to its default value - private static Base64UrlDecoderByte s_base64UrlByteDecoder = default; - private static Base64UrlDecoderChar s_base64UrlCharDecoder = default; -#pragma warning restore CA1805 /// /// Returns the maximum length (in bytes) of the result if you were to decode base 64 encoded text from a span of size . @@ -30,7 +27,7 @@ public static partial class Base64Url /// public static int GetMaxDecodedLength(int base64Length) { -#if NETCOREAPP +#if NET ArgumentOutOfRangeException.ThrowIfNegative(base64Length); (uint whole, uint remainder) = uint.DivRem((uint)base64Length, 4); @@ -66,7 +63,7 @@ public static int GetMaxDecodedLength(int base64Length) /// - Remainder of 1 byte - will cause OperationStatus.InvalidData result. /// public static OperationStatus DecodeFromUtf8(ReadOnlySpan source, Span destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) => - Base64Helper.DecodeFrom(s_base64UrlByteDecoder, source, destination, out bytesConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); + DecodeFrom(default(Base64UrlDecoderByte), source, destination, out bytesConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); /// /// Decodes the span of UTF-8 encoded text in Base64Url into binary data, in-place. @@ -85,7 +82,7 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan source, Span public static int DecodeFromUtf8InPlace(Span buffer) { - OperationStatus status = Base64Helper.DecodeFromUtf8InPlace(s_base64UrlByteDecoder, buffer, out int bytesWritten, ignoreWhiteSpace: true); + OperationStatus status = DecodeFromUtf8InPlace(default(Base64UrlDecoderByte), buffer, out int bytesWritten, ignoreWhiteSpace: true); // Base64.DecodeFromUtf8InPlace returns OperationStatus, therefore doesn't throw. // For Base64Url, this is not an OperationStatus API and thus throws. @@ -201,7 +198,7 @@ public static byte[] DecodeFromUtf8(ReadOnlySpan source) /// public static OperationStatus DecodeFromChars(ReadOnlySpan source, Span destination, out int charsConsumed, out int bytesWritten, bool isFinalBlock = true) => - Base64Helper.DecodeFrom(s_base64UrlCharDecoder, MemoryMarshal.Cast(source), destination, out charsConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); + Base64Helper.DecodeFrom(default(Base64UrlDecoderChar), MemoryMarshal.Cast(source), destination, out charsConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true); private static OperationStatus DecodeWithWhiteSpaceBlockwise(TBase64Decoder decoder, ReadOnlySpan source, Span bytes, ref int bytesConsumed, ref int bytesWritten, bool isFinalBlock = true) where TBase64Decoder : Base64Helper.IBase64Decoder @@ -489,7 +486,7 @@ public static byte[] DecodeFromChars(ReadOnlySpan source) public int SrcLength(bool isFinalBlock, int sourceLength) => isFinalBlock ? sourceLength : sourceLength & ~0x3; -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] [CompExactlyDependsOn(typeof(Ssse3))] @@ -564,34 +561,34 @@ public bool TryDecode256Core( [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe bool TryLoadVector512(byte* src, byte* srcStart, int sourceLength, out Vector512 str) => - Base64Helper.s_base64ByteDecoder.TryLoadVector512(src, srcStart, sourceLength, out str); + default(Base64DecoderByte).TryLoadVector512(src, srcStart, sourceLength, out str); [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(Avx2))] public unsafe bool TryLoadAvxVector256(byte* src, byte* srcStart, int sourceLength, out Vector256 str) => - Base64Helper.s_base64ByteDecoder.TryLoadAvxVector256(src, srcStart, sourceLength, out str); + default(Base64DecoderByte).TryLoadAvxVector256(src, srcStart, sourceLength, out str); [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe bool TryLoadVector128(byte* src, byte* srcStart, int sourceLength, out Vector128 str) => - Base64Helper.s_base64ByteDecoder.TryLoadVector128(src, srcStart, sourceLength, out str); + default(Base64DecoderByte).TryLoadVector128(src, srcStart, sourceLength, out str); [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] public unsafe bool TryLoadArmVector128x4(byte* src, byte* srcStart, int sourceLength, out Vector128 str1, out Vector128 str2, out Vector128 str3, out Vector128 str4) => - Base64Helper.s_base64ByteDecoder.TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out str3, out str4); + default(Base64DecoderByte).TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out str3, out str4); #endif [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe int DecodeFourElements(byte* source, ref sbyte decodingMap) => - Base64Helper.s_base64ByteDecoder.DecodeFourElements(source, ref decodingMap); + default(Base64DecoderByte).DecodeFourElements(source, ref decodingMap); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe int DecodeRemaining(byte* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out uint t3) - => Base64Helper.s_base64ByteDecoder.DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3); + public unsafe int DecodeRemaining(byte* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out uint t3) => + default(Base64DecoderByte).DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan span) => Base64Helper.s_base64ByteDecoder.IndexOfAnyExceptWhiteSpace(span); + public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan span) => default(Base64DecoderByte).IndexOfAnyExceptWhiteSpace(span); [MethodImpl(MethodImplOptions.AggressiveInlining)] public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper(TBase64Decoder decoder, ReadOnlySpan utf8, Span bytes, @@ -601,51 +598,51 @@ public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper(TBas private readonly struct Base64UrlDecoderChar : Base64Helper.IBase64Decoder { - public ReadOnlySpan DecodingMap => s_base64UrlByteDecoder.DecodingMap; + public ReadOnlySpan DecodingMap => default(Base64UrlDecoderByte).DecodingMap; - public ReadOnlySpan VbmiLookup0 => s_base64UrlByteDecoder.VbmiLookup0; + public ReadOnlySpan VbmiLookup0 => default(Base64UrlDecoderByte).VbmiLookup0; - public ReadOnlySpan VbmiLookup1 => s_base64UrlByteDecoder.VbmiLookup1; + public ReadOnlySpan VbmiLookup1 => default(Base64UrlDecoderByte).VbmiLookup1; - public ReadOnlySpan Avx2LutHigh => s_base64UrlByteDecoder.Avx2LutHigh; + public ReadOnlySpan Avx2LutHigh => default(Base64UrlDecoderByte).Avx2LutHigh; - public ReadOnlySpan Avx2LutLow => s_base64UrlByteDecoder.Avx2LutLow; + public ReadOnlySpan Avx2LutLow => default(Base64UrlDecoderByte).Avx2LutLow; - public ReadOnlySpan Avx2LutShift => s_base64UrlByteDecoder.Avx2LutShift; + public ReadOnlySpan Avx2LutShift => default(Base64UrlDecoderByte).Avx2LutShift; - public byte MaskSlashOrUnderscore => s_base64UrlByteDecoder.MaskSlashOrUnderscore; + public byte MaskSlashOrUnderscore => default(Base64UrlDecoderByte).MaskSlashOrUnderscore; - public ReadOnlySpan Vector128LutHigh => s_base64UrlByteDecoder.Vector128LutHigh; + public ReadOnlySpan Vector128LutHigh => default(Base64UrlDecoderByte).Vector128LutHigh; - public ReadOnlySpan Vector128LutLow => s_base64UrlByteDecoder.Vector128LutLow; + public ReadOnlySpan Vector128LutLow => default(Base64UrlDecoderByte).Vector128LutLow; - public ReadOnlySpan Vector128LutShift => s_base64UrlByteDecoder.Vector128LutShift; + public ReadOnlySpan Vector128LutShift => default(Base64UrlDecoderByte).Vector128LutShift; - public ReadOnlySpan AdvSimdLutOne3 => s_base64UrlByteDecoder.AdvSimdLutOne3; + public ReadOnlySpan AdvSimdLutOne3 => default(Base64UrlDecoderByte).AdvSimdLutOne3; - public uint AdvSimdLutTwo3Uint1 => s_base64UrlByteDecoder.AdvSimdLutTwo3Uint1; + public uint AdvSimdLutTwo3Uint1 => default(Base64UrlDecoderByte).AdvSimdLutTwo3Uint1; - public int GetMaxDecodedLength(int sourceLength) => s_base64UrlByteDecoder.GetMaxDecodedLength(sourceLength); + public int GetMaxDecodedLength(int sourceLength) => default(Base64UrlDecoderByte).GetMaxDecodedLength(sourceLength); - public bool IsInvalidLength(int bufferLength) => s_base64UrlByteDecoder.IsInvalidLength(bufferLength); + public bool IsInvalidLength(int bufferLength) => default(Base64UrlDecoderByte).IsInvalidLength(bufferLength); - public bool IsValidPadding(uint padChar) => s_base64UrlByteDecoder.IsValidPadding(padChar); + public bool IsValidPadding(uint padChar) => default(Base64UrlDecoderByte).IsValidPadding(padChar); - public int SrcLength(bool isFinalBlock, int sourceLength) => s_base64UrlByteDecoder.SrcLength(isFinalBlock, sourceLength); + public int SrcLength(bool isFinalBlock, int sourceLength) => default(Base64UrlDecoderByte).SrcLength(isFinalBlock, sourceLength); -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] [CompExactlyDependsOn(typeof(Ssse3))] public bool TryDecode128Core(Vector128 str, Vector128 hiNibbles, Vector128 maskSlashOrUnderscore, Vector128 mask8F, Vector128 lutLow, Vector128 lutHigh, Vector128 lutShift, Vector128 shiftForUnderscore, out Vector128 result) => - s_base64UrlByteDecoder.TryDecode128Core(str, hiNibbles, maskSlashOrUnderscore, mask8F, lutLow, lutHigh, lutShift, shiftForUnderscore, out result); + default(Base64UrlDecoderByte).TryDecode128Core(str, hiNibbles, maskSlashOrUnderscore, mask8F, lutLow, lutHigh, lutShift, shiftForUnderscore, out result); [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(Avx2))] public bool TryDecode256Core(Vector256 str, Vector256 hiNibbles, Vector256 maskSlashOrUnderscore, Vector256 lutLow, Vector256 lutHigh, Vector256 lutShift, Vector256 shiftForUnderscore, out Vector256 result) => - s_base64UrlByteDecoder.TryDecode256Core(str, hiNibbles, maskSlashOrUnderscore, lutLow, lutHigh, lutShift, shiftForUnderscore, out result); + default(Base64UrlDecoderByte).TryDecode256Core(str, hiNibbles, maskSlashOrUnderscore, lutLow, lutHigh, lutShift, shiftForUnderscore, out result); [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe bool TryLoadVector512(ushort* src, ushort* srcStart, int sourceLength, out Vector512 str) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs index a0bb7652bef84a..b19b70f14cf863 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs @@ -4,22 +4,17 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if NETCOREAPP +#if NET using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; #endif -using static System.Buffers.Text.Base64; +using static System.Buffers.Text.Base64Helper; namespace System.Buffers.Text { public static partial class Base64Url { -#pragma warning disable CA1805 // Member 's_base64UrlByteEncoder' is explicitly initialized to its default value - private static Base64UrlEncoderByte s_base64UrlByteEncoder = default; - private static Base64UrlEncoderChar s_base64UrlCharEncoder = default; -#pragma warning restore CA1805 - /// /// Encodes the span of binary data into UTF-8 encoded text represented as Base64Url. /// @@ -33,7 +28,7 @@ public static partial class Base64Url /// This implementation of the base64url encoding omits the optional padding characters. public static OperationStatus EncodeToUtf8(ReadOnlySpan source, Span destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) => - Base64Helper.EncodeTo(s_base64UrlByteEncoder, source, destination, out bytesConsumed, out bytesWritten, isFinalBlock); + Base64Helper.EncodeTo(default(Base64UrlEncoderByte), source, destination, out bytesConsumed, out bytesWritten, isFinalBlock); /// /// Returns the length (in bytes) of the result if you were to encode binary data within a byte span of size . @@ -43,7 +38,7 @@ public static OperationStatus EncodeToUtf8(ReadOnlySpan source, /// public static int GetEncodedLength(int bytesLength) { -#if NETCOREAPP +#if NET ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)bytesLength, Base64Helper.MaximumEncodeLength); (uint whole, uint remainder) = uint.DivRem((uint)bytesLength, 3); @@ -110,7 +105,7 @@ public static byte[] EncodeToUtf8(ReadOnlySpan source) /// This implementation of the base64url encoding omits the optional padding characters. public static OperationStatus EncodeToChars(ReadOnlySpan source, Span destination, out int bytesConsumed, out int charsWritten, bool isFinalBlock = true) => - Base64Helper.EncodeTo(s_base64UrlCharEncoder, source, MemoryMarshal.Cast(destination), out bytesConsumed, out charsWritten, isFinalBlock); + EncodeTo(default(Base64UrlEncoderChar), source, MemoryMarshal.Cast(destination), out bytesConsumed, out charsWritten, isFinalBlock); /// /// Encodes the span of binary data into unicode ASCII chars represented as Base64Url. @@ -156,7 +151,7 @@ public static char[] EncodeToChars(ReadOnlySpan source) /// This implementation of the base64url encoding omits the optional padding characters. public static unsafe string EncodeToString(ReadOnlySpan source) { -#if NETCOREAPP +#if NET int encodedLength = GetEncodedLength(source.Length); #pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type @@ -219,7 +214,7 @@ public static bool TryEncodeToUtf8(ReadOnlySpan source, Span destina /// This implementation of the base64url encoding omits the optional padding characters. public static bool TryEncodeToUtf8InPlace(Span buffer, int dataLength, out int bytesWritten) { - OperationStatus status = Base64Helper.EncodeToUtf8InPlace(s_base64UrlByteEncoder, buffer, dataLength, out bytesWritten); + OperationStatus status = EncodeToUtf8InPlace(default(Base64UrlEncoderByte), buffer, dataLength, out bytesWritten); return status == OperationStatus.Done; } @@ -297,50 +292,50 @@ public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, byte* dest, ref byt } } -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe void StoreVector512ToDestination(byte* dest, byte* destStart, int destLength, Vector512 str) => - Base64Helper.s_base64ByteEncoder.StoreVector512ToDestination(dest, destStart, destLength, str); + default(Base64EncoderByte).StoreVector512ToDestination(dest, destStart, destLength, str); [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(Avx2))] public unsafe void StoreVector256ToDestination(byte* dest, byte* destStart, int destLength, Vector256 str) => - Base64Helper.s_base64ByteEncoder.StoreVector256ToDestination(dest, destStart, destLength, str); + default(Base64EncoderByte).StoreVector256ToDestination(dest, destStart, destLength, str); [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe void StoreVector128ToDestination(byte* dest, byte* destStart, int destLength, Vector128 str) => - Base64Helper.s_base64ByteEncoder.StoreVector128ToDestination(dest, destStart, destLength, str); + default(Base64EncoderByte).StoreVector128ToDestination(dest, destStart, destLength, str); [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] public unsafe void StoreArmVector128x4ToDestination(byte* dest, byte* destStart, int destLength, Vector128 res1, Vector128 res2, Vector128 res3, Vector128 res4) => - Base64Helper.s_base64ByteEncoder.StoreArmVector128x4ToDestination(dest, destStart, destLength, res1, res2, res3, res4); + default(Base64EncoderByte).StoreArmVector128x4ToDestination(dest, destStart, destLength, res1, res2, res3, res4); #endif [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe void EncodeThreeAndWrite(byte* threeBytes, byte* destination, ref byte encodingMap) => - Base64Helper.s_base64ByteEncoder.EncodeThreeAndWrite(threeBytes, destination, ref encodingMap); + default(Base64EncoderByte).EncodeThreeAndWrite(threeBytes, destination, ref encodingMap); } private readonly struct Base64UrlEncoderChar : Base64Helper.IBase64Encoder { - public ReadOnlySpan EncodingMap => s_base64UrlByteEncoder.EncodingMap; + public ReadOnlySpan EncodingMap => default(Base64UrlEncoderByte).EncodingMap; - public sbyte Avx2LutChar62 => s_base64UrlByteEncoder.Avx2LutChar62; + public sbyte Avx2LutChar62 => default(Base64UrlEncoderByte).Avx2LutChar62; - public sbyte Avx2LutChar63 => s_base64UrlByteEncoder.Avx2LutChar63; + public sbyte Avx2LutChar63 => default(Base64UrlEncoderByte).Avx2LutChar63; - public ReadOnlySpan AdvSimdLut4 => s_base64UrlByteEncoder.AdvSimdLut4; + public ReadOnlySpan AdvSimdLut4 => default(Base64UrlEncoderByte).AdvSimdLut4; - public uint Ssse3AdvSimdLutE3 => s_base64UrlByteEncoder.Ssse3AdvSimdLutE3; + public uint Ssse3AdvSimdLutE3 => default(Base64UrlEncoderByte).Ssse3AdvSimdLutE3; - public int IncrementPadTwo => s_base64UrlByteEncoder.IncrementPadTwo; + public int IncrementPadTwo => default(Base64UrlEncoderByte).IncrementPadTwo; - public int IncrementPadOne => s_base64UrlByteEncoder.IncrementPadOne; + public int IncrementPadOne => default(Base64UrlEncoderByte).IncrementPadOne; public int GetMaxSrcLength(int srcLength, int destLength) => - s_base64UrlByteEncoder.GetMaxSrcLength(srcLength, destLength); + default(Base64UrlEncoderByte).GetMaxSrcLength(srcLength, destLength); public uint GetInPlaceDestinationLength(int encodedLength, int _) => 0; // not used for char encoding @@ -394,7 +389,7 @@ public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, ushort* dest, ref b } } -#if NETCOREAPP +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe void StoreVector512ToDestination(ushort* dest, ushort* destStart, int destLength, Vector512 str) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs index 1893f29aef57af..ea785fc2ca7420 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs @@ -7,11 +7,6 @@ namespace System.Buffers.Text { public static partial class Base64Url { -#pragma warning disable CA1805 // Member 's_base64ByteEncoder' is explicitly initialized to its default value - private static Base64UrlByteValidatable s_base64UrlByteValidatable = default; - private static Base64UrlCharValidatable s_base64UrlCharValidatable = default; -#pragma warning restore CA1805 - /// Validates that the specified span of text is comprised of valid base-64 encoded data. /// A span of text to validate. /// if contains a valid, decodable sequence of base-64 encoded data; otherwise, . @@ -22,7 +17,7 @@ public static partial class Base64Url /// Any amount of whitespace is allowed anywhere in the input, where whitespace is defined as the characters ' ', '\t', '\r', or '\n'. /// public static bool IsValid(ReadOnlySpan base64UrlText) => - Base64Helper.IsValid(s_base64UrlCharValidatable, base64UrlText, out _); + Base64Helper.IsValid(default(Base64UrlCharValidatable), base64UrlText, out _); /// Validates that the specified span of text is comprised of valid base-64 encoded data. /// A span of text to validate. @@ -35,7 +30,7 @@ public static bool IsValid(ReadOnlySpan base64UrlText) => /// Any amount of whitespace is allowed anywhere in the input, where whitespace is defined as the characters ' ', '\t', '\r', or '\n'. /// public static bool IsValid(ReadOnlySpan base64UrlText, out int decodedLength) => - Base64Helper.IsValid(s_base64UrlCharValidatable, base64UrlText, out decodedLength); + Base64Helper.IsValid(default(Base64UrlCharValidatable), base64UrlText, out decodedLength); /// Validates that the specified span of UTF-8 text is comprised of valid base-64 encoded data. /// A span of UTF-8 text to validate. @@ -44,7 +39,7 @@ public static bool IsValid(ReadOnlySpan base64UrlText, out int decodedLeng /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes). /// public static bool IsValid(ReadOnlySpan utf8Base64UrlText) => - Base64Helper.IsValid(s_base64UrlByteValidatable, utf8Base64UrlText, out _); + Base64Helper.IsValid(default(Base64UrlByteValidatable), utf8Base64UrlText, out _); /// Validates that the specified span of UTF-8 text is comprised of valid base-64 encoded data. /// A span of UTF-8 text to validate. @@ -54,13 +49,13 @@ public static bool IsValid(ReadOnlySpan utf8Base64UrlText) => /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes). /// public static bool IsValid(ReadOnlySpan utf8Base64UrlText, out int decodedLength) => - Base64Helper.IsValid(s_base64UrlByteValidatable, utf8Base64UrlText, out decodedLength); + Base64Helper.IsValid(default(Base64UrlByteValidatable), utf8Base64UrlText, out decodedLength); private const uint UrlEncodingPad = '%'; // allowed for url padding private readonly struct Base64UrlCharValidatable : Base64Helper.IBase64Validatable { -#if NETCOREAPP +#if NET private static readonly SearchValues s_validBase64UrlChars = SearchValues.Create("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); public int IndexOfAnyExcept(ReadOnlySpan span) => span.IndexOfAnyExcept(s_validBase64UrlChars); @@ -73,25 +68,24 @@ public int DecodeValue(char value) return -2; } - return s_base64UrlByteDecoder.DecodingMap[value]; + return default(Base64UrlDecoderByte).DecodingMap[value]; } #endif public bool IsWhiteSpace(char value) => Base64Helper.IsWhiteSpace(value); public bool IsEncodingPad(char value) => value == Base64Helper.EncodingPad || value == UrlEncodingPad; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ValidateAndDecodeLength(int length, int paddingCount, out int decodedLength) => - s_base64UrlByteValidatable.ValidateAndDecodeLength(length, paddingCount, out decodedLength); + default(Base64UrlByteValidatable).ValidateAndDecodeLength(length, paddingCount, out decodedLength); } private readonly struct Base64UrlByteValidatable : Base64Helper.IBase64Validatable { -#if NETCOREAPP - private static readonly SearchValues s_validBase64UrlChars = SearchValues.Create(s_base64UrlByteEncoder.EncodingMap); +#if NET + private static readonly SearchValues s_validBase64UrlChars = SearchValues.Create(default(Base64UrlEncoderByte).EncodingMap); public int IndexOfAnyExcept(ReadOnlySpan span) => span.IndexOfAnyExcept(s_validBase64UrlChars); #else - public int DecodeValue(byte value) => - s_base64UrlByteDecoder.DecodingMap[value]; + public int DecodeValue(byte value) => default(Base64UrlDecoderByte).DecodingMap[value]; #endif public bool IsWhiteSpace(byte value) => Base64Helper.IsWhiteSpace(value); public bool IsEncodingPad(byte value) => value == Base64Helper.EncodingPad || value == UrlEncodingPad; @@ -99,7 +93,7 @@ public int DecodeValue(byte value) => public bool ValidateAndDecodeLength(int length, int paddingCount, out int decodedLength) { // Padding is optional for Base64Url, so need to account remainder. If remainder is 1, then it's invalid. -#if NETCOREAPP +#if NET (uint whole, uint remainder) = uint.DivRem((uint)(length), 4); if (remainder == 1 || (remainder > 1 && (remainder - paddingCount == 1 || paddingCount == remainder))) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Validator.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Validator.cs index fb121b6b46439c..c2e4ad82a4ba0d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Validator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Validator.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using static System.Buffers.Text.Base64Helper; + namespace System.Buffers.Text { public static partial class Base64 @@ -15,7 +17,7 @@ public static partial class Base64 /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n'. /// public static bool IsValid(ReadOnlySpan base64Text) => - Base64Helper.IsValid(Base64Helper.s_base64CharValidatable, base64Text, out _); + Base64Helper.IsValid(default(Base64CharValidatable), base64Text, out _); /// Validates that the specified span of text is comprised of valid base-64 encoded data. /// A span of text to validate. @@ -28,7 +30,7 @@ public static bool IsValid(ReadOnlySpan base64Text) => /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n'. /// public static bool IsValid(ReadOnlySpan base64Text, out int decodedLength) => - Base64Helper.IsValid(Base64Helper.s_base64CharValidatable, base64Text, out decodedLength); + Base64Helper.IsValid(default(Base64CharValidatable), base64Text, out decodedLength); /// Validates that the specified span of UTF-8 text is comprised of valid base-64 encoded data. /// A span of UTF-8 text to validate. @@ -39,7 +41,7 @@ public static bool IsValid(ReadOnlySpan base64Text, out int decodedLength) /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes). /// public static bool IsValid(ReadOnlySpan base64TextUtf8) => - Base64Helper.IsValid(Base64Helper.s_base64ByteValidatable, base64TextUtf8, out _); + Base64Helper.IsValid(default(Base64ByteValidatable), base64TextUtf8, out _); /// Validates that the specified span of UTF-8 text is comprised of valid base-64 encoded data. /// A span of UTF-8 text to validate. @@ -51,7 +53,7 @@ public static bool IsValid(ReadOnlySpan base64TextUtf8) => /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes). /// public static bool IsValid(ReadOnlySpan base64TextUtf8, out int decodedLength) => - Base64Helper.IsValid(Base64Helper.s_base64ByteValidatable, base64TextUtf8, out decodedLength); + Base64Helper.IsValid(default(Base64ByteValidatable), base64TextUtf8, out decodedLength); } }