< Summary

Line coverage
69%
Covered lines: 208
Uncovered lines: 90
Coverable lines: 298
Total lines: 1080
Line coverage: 69.7%
Branch coverage
51%
Covered branches: 37
Total branches: 72
Branch coverage: 51.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: GetMaxDecodedLength(...)100%22100%
File 1: DecodeFromUtf8(...)100%11100%
File 1: DecodeFromUtf8InPlace(...)100%22100%
File 1: DecodeFromUtf8(...)0%440%
File 1: TryDecodeFromUtf8(...)50%4480%
File 1: DecodeFromUtf8(...)0%880%
File 1: DecodeFromChars(...)100%11100%
File 1: DecodeFromChars(...)0%440%
File 1: TryDecodeFromChars(...)0%220%
File 1: DecodeFromChars(...)0%660%
File 1: GetMaxDecodedLength(...)100%11100%
File 1: IsInvalidLength(...)100%11100%
File 1: IsValidPadding(...)100%22100%
File 1: SrcLength(...)100%22100%
File 1: TryDecode128Core(...)100%22100%
File 1: TryDecode256Core(...)100%22100%
File 1: TryLoadVector512(...)100%11100%
File 1: TryLoadAvxVector256(...)100%11100%
File 1: TryLoadVector128(...)100%11100%
File 1: TryLoadArmVector128x4(...)100%110%
File 1: DecodeFourElements(...)100%11100%
File 1: DecodeRemaining(...)100%11100%
File 1: IndexOfAnyExceptWhiteSpace(...)100%11100%
File 1: DecodeWithWhiteSpaceBlockwiseWrapper(...)100%11100%
File 1: GetMaxDecodedLength(...)100%11100%
File 1: IsInvalidLength(...)100%110%
File 1: IsValidPadding(...)100%11100%
File 1: SrcLength(...)100%11100%
File 1: TryDecode128Core(...)100%11100%
File 1: TryDecode256Core(...)100%11100%
File 1: TryLoadVector512(...)100%11100%
File 1: TryLoadAvxVector256(...)100%11100%
File 1: TryLoadVector128(...)100%11100%
File 1: TryLoadArmVector128x4(...)100%110%
File 1: DecodeFourElements(...)100%11100%
File 1: DecodeRemaining(...)100%11100%
File 1: IndexOfAnyExceptWhiteSpace(...)100%110%
File 1: DecodeWithWhiteSpaceBlockwiseWrapper(...)100%110%
File 2: EncodeToUtf8(...)100%110%
File 2: GetEncodedLength(...)100%22100%
File 2: EncodeToUtf8(...)0%220%
File 2: EncodeToUtf8(...)100%110%
File 2: EncodeToChars(...)100%11100%
File 2: EncodeToChars(...)0%220%
File 2: EncodeToChars(...)100%110%
File 2: EncodeToString(...)50%22100%
File 2: TryEncodeToChars(...)100%110%
File 2: TryEncodeToUtf8(...)100%110%
File 2: TryEncodeToUtf8InPlace(...)100%11100%
File 2: GetMaxSrcLength(...)50%44100%
File 2: GetInPlaceDestinationLength(...)100%22100%
File 2: GetMaxEncodedLength(...)100%11100%
File 2: EncodeOneOptionallyPadTwo(...)100%11100%
File 2: EncodeTwoOptionallyPadOne(...)100%11100%
File 2: StoreVector512ToDestination(...)100%110%
File 2: StoreVector256ToDestination(...)100%110%
File 2: StoreVector128ToDestination(...)100%110%
File 2: StoreArmVector128x4ToDestination(...)100%110%
File 2: EncodeThreeAndWrite(...)100%110%
File 2: GetMaxSrcLength(...)100%11100%
File 2: GetInPlaceDestinationLength(...)100%110%
File 2: GetMaxEncodedLength(...)100%110%
File 2: EncodeOneOptionallyPadTwo(...)100%11100%
File 2: EncodeTwoOptionallyPadOne(...)100%11100%
File 2: StoreVector512ToDestination(...)100%11100%
File 2: StoreVector256ToDestination(...)100%11100%
File 2: StoreVector128ToDestination(...)100%11100%
File 2: StoreArmVector128x4ToDestination(...)100%110%
File 2: EncodeThreeAndWrite(...)100%11100%
File 3: IsValid(...)100%110%
File 3: IsValid(...)100%110%
File 3: IsValid(...)100%110%
File 3: IsValid(...)100%11100%
File 3: .cctor()100%110%
File 3: IndexOfAnyExcept(...)100%110%
File 3: IsWhiteSpace(...)100%110%
File 3: IsEncodingPad(...)0%220%
File 3: ValidateAndDecodeLength(...)100%110%
File 3: .cctor()100%11100%
File 3: IndexOfAnyExcept(...)100%11100%
File 3: IsWhiteSpace(...)100%11100%
File 3: IsEncodingPad(...)100%22100%
File 3: ValidateAndDecodeLength(...)100%1414100%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Runtime.CompilerServices;
 7using System.Runtime.InteropServices;
 8#if NET
 9using System.Runtime.Intrinsics;
 10using System.Runtime.Intrinsics.Arm;
 11using System.Runtime.Intrinsics.X86;
 12#endif
 13using static System.Buffers.Text.Base64Helper;
 14
 15namespace System.Buffers.Text
 16{
 17    // AVX2 and Vector128 version based on https://github.com/gfoidl/Base64/blob/5383320e28cac6c7ac6f86502fb05d23a048a21
 18#pragma warning disable 1591 // TODO: Document this API. https://github.com/dotnet/runtime/issues/105974
 19    public static partial class Base64Url
 20#pragma warning restore 1591
 21    {
 22        private const int MaxStackallocThreshold = 256;
 23
 24        /// <summary>
 25        /// Returns the maximum length (in bytes) of the result if you were to decode Base64Url-encoded text from a span
 26        /// </summary>
 27        /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="base64Length"/> is less than 0.
 28        /// </exception>
 29        public static int GetMaxDecodedLength(int base64Length)
 30        {
 31#if NET
 7713132            ArgumentOutOfRangeException.ThrowIfNegative(base64Length);
 33
 7713134            (uint whole, uint remainder) = uint.DivRem((uint)base64Length, 4);
 35
 7713136            return (int)(whole * 3 + (remainder > 0 ? remainder - 1 : 0));
 37#else
 38            if (base64Length < 0)
 39            {
 40                throw new ArgumentOutOfRangeException(nameof(base64Length));
 41            }
 42
 43            int remainder = (int)((uint)base64Length % 4);
 44
 45            return (base64Length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0);
 46#endif
 47        }
 48
 49        /// <summary>
 50        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 51        /// </summary>
 52        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 53        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 54        /// <param name="bytesConsumed">When this method returns, contains the number of input bytes consumed during the
 55        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 56        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to decod
 57        /// such as when calling in a loop. Calls with <see langword="false"/> should be followed up with another call w
 58        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 59        /// <remarks>
 60        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 61        /// If the <paramref name="source"/> length is not a multiple of 4 and <paramref name="isFinalBlock"/> is <see l
 62        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 63        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 64        /// - Remainder of 1 byte - will cause OperationStatus.InvalidData result.
 65        /// </remarks>
 66        public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesCon
 244967            DecodeFrom(default(Base64UrlDecoderByte), source, destination, out bytesConsumed, out bytesWritten, isFinalB
 68
 69        /// <summary>
 70        /// Decodes the span of UTF-8 encoded text in Base64Url into binary data, in-place.
 71        /// The decoded binary output is smaller than the text data contained in the input (the operation deflates the d
 72        /// </summary>
 73        /// <param name="buffer">The input span which contains the Base64Url text data that needs to be decoded.</param>
 74        /// <returns>The number of bytes written into <paramref name="buffer"/>. This can be used to slice the output fo
 75        /// <exception cref="FormatException"><paramref name="buffer"/> contains an invalid Base64Url character,
 76        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 77        /// <remarks>
 78        /// As padding is optional for Base64Url the <paramref name="buffer"/> length not required to be a multiple of 4
 79        /// If the <paramref name="buffer"/> length is not a multiple of 4 the remainders decoded accordingly:
 80        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 81        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 82        /// - Remainder of 1 byte - is invalid input, causes FormatException.
 83        /// </remarks>
 84        public static int DecodeFromUtf8InPlace(Span<byte> buffer)
 85        {
 327686            OperationStatus status = DecodeFromUtf8InPlace<Base64UrlDecoderByte>(default, buffer, out int bytesWritten, 
 87
 88            // Base64.DecodeFromUtf8InPlace returns OperationStatus, therefore doesn't throw.
 89            // For Base64Url, this is not an OperationStatus API and thus throws.
 327690            if (status == OperationStatus.InvalidData)
 91            {
 82792                throw new FormatException(SR.Format_BadBase64Char);
 93            }
 94
 244995            Debug.Assert(status is OperationStatus.Done);
 244996            return bytesWritten;
 97        }
 98
 99        /// <summary>
 100        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 101        /// </summary>
 102        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 103        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 104        /// <returns>The number of bytes written into <paramref name="destination"/>. This can be used to slice the outp
 105        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the de
 106        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 107        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 108        /// <remarks>
 109        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 110        /// If the <paramref name="source"/> length is not a multiple of 4 the remainders decoded accordingly:
 111        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 112        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 113        /// - Remainder of 1 byte - is invalid input, causes FormatException.
 114        /// </remarks>
 115        public static int DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination)
 116        {
 0117            OperationStatus status = DecodeFromUtf8(source, destination, out _, out int bytesWritten);
 118
 0119            if (status == OperationStatus.Done)
 120            {
 0121                return bytesWritten;
 122            }
 123
 0124            if (status == OperationStatus.DestinationTooSmall)
 125            {
 0126                throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 127            }
 128
 0129            Debug.Assert(status is OperationStatus.InvalidData);
 0130            throw new FormatException(SR.Format_BadBase64Char);
 131        }
 132
 133        /// <summary>
 134        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 135        /// </summary>
 136        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 137        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 138        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 139        /// <returns><see langword="true"/> if bytes decoded successfully, otherwise <see langword="false"/>.</returns>
 140        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 141        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 142        public static bool TryDecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
 143        {
 811144            OperationStatus status = DecodeFromUtf8(source, destination, out _, out bytesWritten);
 145
 811146            if (status == OperationStatus.InvalidData)
 147            {
 0148                throw new FormatException(SR.Format_BadBase64Char);
 149            }
 150
 811151            Debug.Assert(status is OperationStatus.Done or OperationStatus.DestinationTooSmall);
 811152            return status == OperationStatus.Done;
 153        }
 154
 155        /// <summary>
 156        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 157        /// </summary>
 158        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 159        /// <returns>A byte array which contains the result of the decoding operation.</returns>
 160        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 161        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 162        public static unsafe byte[] DecodeFromUtf8(ReadOnlySpan<byte> source)
 163        {
 0164            int upperBound = GetMaxDecodedLength(source.Length);
 0165            byte[]? rented = null;
 166
 0167            Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
 0168                ? stackalloc byte[MaxStackallocThreshold]
 0169                : (rented = ArrayPool<byte>.Shared.Rent(upperBound));
 170
 0171            OperationStatus status = DecodeFromUtf8(source, destination, out _, out int bytesWritten);
 0172            Debug.Assert(status is OperationStatus.Done or OperationStatus.InvalidData);
 0173            byte[] ret = destination.Slice(0, bytesWritten).ToArray();
 174
 0175            if (rented is not null)
 176            {
 0177                ArrayPool<byte>.Shared.Return(rented);
 178            }
 179
 0180            return status == OperationStatus.Done ? ret : throw new FormatException(SR.Format_BadBase64Char);
 181        }
 182
 183        /// <summary>
 184        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 185        /// </summary>
 186        /// <param name="source">The input span which contains unicode ASCII chars in Base64Url that needs to be decoded
 187        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 188        /// <param name="charsConsumed">When this method returns, contains the number of input chars consumed during the
 189        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 190        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to decod
 191        /// such as when calling in a loop. Calls with <see langword="false"/> should be followed up with another call w
 192        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 193        /// <remarks>
 194        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 195        /// If the <paramref name="source"/> length is not a multiple of 4 and <paramref name="isFinalBlock"/> is <see l
 196        /// - Remainder of 3 chars - decoded into 2 bytes data, decoding succeeds.
 197        /// - Remainder of 2 chars - decoded into 1 byte data. decoding succeeds.
 198        /// - Remainder of 1 char - will cause OperationStatus.InvalidData result.
 199        /// </remarks>
 200        public static OperationStatus DecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination,
 201            out int charsConsumed, out int bytesWritten, bool isFinalBlock = true) =>
 3276202            DecodeFrom(default(Base64UrlDecoderChar), MemoryMarshal.Cast<char, ushort>(source), destination,
 3276203                out charsConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true);
 204
 205        /// <summary>
 206        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 207        /// </summary>
 208        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 209        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 210        /// <returns>The number of bytes written into the output span. This can be used to slice the output for subseque
 211        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the de
 212        /// <exception cref="FormatException"><paramref name="source"/> contains a invalid Base64Url character,
 213        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 214        public static int DecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination)
 215        {
 0216            OperationStatus status = DecodeFromChars(source, destination, out _, out int bytesWritten);
 217
 0218            if (status == OperationStatus.Done)
 219            {
 0220                return bytesWritten;
 221            }
 222
 0223            if (status == OperationStatus.DestinationTooSmall)
 224            {
 0225                throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 226            }
 227
 0228            Debug.Assert(status == OperationStatus.InvalidData);
 0229            throw new FormatException(SR.Format_BadBase64Char);
 230        }
 231
 232        /// <summary>
 233        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 234        /// </summary>
 235        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 236        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 237        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 238        /// <returns><see langword="true"/> if bytes decoded successfully, otherwise <see langword="false"/>.</returns>
 239        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 240        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 241        public static bool TryDecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination, out int bytesWritten)
 242        {
 0243            OperationStatus status = DecodeFromChars(source, destination, out _, out bytesWritten);
 244
 0245            if (status == OperationStatus.InvalidData)
 246            {
 0247                throw new FormatException(SR.Format_BadBase64Char);
 248            }
 249
 0250            return status == OperationStatus.Done;
 251        }
 252
 253        /// <summary>
 254        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 255        /// </summary>
 256        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 257        /// <returns>A byte array which contains the result of the decoding operation.</returns>
 258        /// <exception cref="FormatException"><paramref name="source"/> contains a invalid Base64Url character,
 259        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 260        public static unsafe byte[] DecodeFromChars(ReadOnlySpan<char> source)
 261        {
 0262            int upperBound = GetMaxDecodedLength(source.Length);
 0263            byte[]? rented = null;
 264
 0265            Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
 0266                ? stackalloc byte[MaxStackallocThreshold]
 0267                : (rented = ArrayPool<byte>.Shared.Rent(upperBound));
 268
 0269            OperationStatus status = DecodeFromChars(source, destination, out _, out int bytesWritten);
 0270            byte[] ret = destination.Slice(0, bytesWritten).ToArray();
 271
 0272            if (rented is not null)
 273            {
 0274                ArrayPool<byte>.Shared.Return(rented);
 275            }
 276
 0277            return status == OperationStatus.Done ? ret : throw new FormatException(SR.Format_BadBase64Char);
 278        }
 279
 280        private readonly struct Base64UrlDecoderByte : IBase64Decoder<byte>
 281        {
 282            public ReadOnlySpan<sbyte> DecodingMap =>
 144005283                [
 144005284                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005285                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005286                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1,         //62 is placed at index 45 (
 144005287                    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,         //52-61 are placed at index 
 144005288                    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
 144005289                    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,         //0-25 are placed at index 6
 144005290                    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
 144005291                    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,         //26-51 are placed at index 
 144005292                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,         // Bytes over 122 ('z') are 
 144005293                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,         // Hence, padding the map wi
 144005294                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005295                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005296                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005297                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005298                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005299                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 144005300                ];
 301
 302            public ReadOnlySpan<uint> VbmiLookup0 =>
 29199303                [
 29199304                    0x80808080, 0x80808080, 0x80808080, 0x80808080,
 29199305                    0x80808080, 0x80808080, 0x80808080, 0x80808080,
 29199306                    0x80808080, 0x80808080, 0x80808080, 0x80803e80,
 29199307                    0x37363534, 0x3b3a3938, 0x80803d3c, 0x80808080
 29199308                ];
 309
 310            public ReadOnlySpan<uint> VbmiLookup1 =>
 29199311                [
 29199312                    0x02010080, 0x06050403, 0x0a090807, 0x0e0d0c0b,
 29199313                    0x1211100f, 0x16151413, 0x80191817, 0x3f808080,
 29199314                    0x1c1b1a80, 0x201f1e1d, 0x24232221, 0x28272625,
 29199315                    0x2c2b2a29, 0x302f2e2d, 0x80333231, 0x80808080
 29199316                ];
 317
 318            public ReadOnlySpan<sbyte> Avx2LutHigh =>
 31339319                [
 31339320                    0x00, 0x00, 0x2d, 0x39,
 31339321                    0x4f, 0x5a, 0x6f, 0x7a,
 31339322                    0x00, 0x00, 0x00, 0x00,
 31339323                    0x00, 0x00, 0x00, 0x00,
 31339324                    0x00, 0x00, 0x2d, 0x39,
 31339325                    0x4f, 0x5a, 0x6f, 0x7a,
 31339326                    0x00, 0x00, 0x00, 0x00,
 31339327                    0x00, 0x00, 0x00, 0x00
 31339328                ];
 329
 330            public ReadOnlySpan<sbyte> Avx2LutLow =>
 31339331                [
 31339332                    0x01, 0x01, 0x2d, 0x30,
 31339333                    0x41, 0x50, 0x61, 0x70,
 31339334                    0x01, 0x01, 0x01, 0x01,
 31339335                    0x01, 0x01, 0x01, 0x01,
 31339336                    0x01, 0x01, 0x2d, 0x30,
 31339337                    0x41, 0x50, 0x61, 0x70,
 31339338                    0x01, 0x01, 0x01, 0x01,
 31339339                    0x01, 0x01, 0x01, 0x01
 31339340                ];
 341
 342            public ReadOnlySpan<sbyte> Avx2LutShift =>
 31339343                [
 31339344                    0,   0,  17,   4,
 31339345                  -65, -65, -71, -71,
 31339346                    0,   0,   0,   0,
 31339347                    0,   0,   0,   0,
 31339348                    0,   0,  17,   4,
 31339349                  -65, -65, -71, -71,
 31339350                    0,   0,   0,   0,
 31339351                    0,   0,   0,   0
 31339352                ];
 353
 64290354            public byte MaskSlashOrUnderscore => (byte)'_'; // underscore
 355
 32951356            public ReadOnlySpan<int> Vector128LutHigh => [0x392d0000, 0x7a6f5a4f, 0x00000000, 0x00000000];
 357
 32951358            public ReadOnlySpan<int> Vector128LutLow => [0x302d0101, 0x70615041, 0x01010101, 0x01010101];
 359
 32951360            public ReadOnlySpan<uint> Vector128LutShift => [0x04110000, 0xb9b9bfbf, 0x00000000, 0x00000000];
 361
 0362            public ReadOnlySpan<uint> AdvSimdLutOne3 => [0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3EFF];
 363
 0364            public uint AdvSimdLutTwo3Uint1 => 0x1B1AFF3F;
 365
 74682366            public int GetMaxDecodedLength(int sourceLength) => Base64Url.GetMaxDecodedLength(sourceLength);
 367
 69005368            public bool IsInvalidLength(int bufferLength) => (bufferLength & 3) == 1; // One byte cannot be decoded comp
 369
 152711370            public bool IsValidPadding(uint padChar) => padChar is EncodingPad or UrlEncodingPad;
 371
 74682372            public int SrcLength(bool isFinalBlock, int sourceLength) => isFinalBlock ? sourceLength : sourceLength & ~0
 373
 374#if NET
 375            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 376            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 377            [CompExactlyDependsOn(typeof(Ssse3))]
 378            public bool TryDecode128Core(
 379                Vector128<byte> str,
 380                Vector128<byte> hiNibbles,
 381                Vector128<byte> maskSlashOrUnderscore,
 382                Vector128<byte> mask8F,
 383                Vector128<byte> lutLow,
 384                Vector128<byte> lutHigh,
 385                Vector128<sbyte> lutShift,
 386                Vector128<byte> shiftForUnderscore,
 387                out Vector128<byte> result)
 388            {
 38515389                Vector128<byte> lowerBound = SimdShuffle(lutLow, hiNibbles, mask8F);
 38515390                Vector128<byte> upperBound = SimdShuffle(lutHigh, hiNibbles, mask8F);
 391
 38515392                Vector128<byte> below = Vector128.LessThan(str, lowerBound);
 38515393                Vector128<byte> above = Vector128.GreaterThan(str, upperBound);
 38515394                Vector128<byte> eq5F = Vector128.Equals(str, maskSlashOrUnderscore);
 395
 396                // Take care as arguments are flipped in order!
 38515397                Vector128<byte> outside = Vector128.AndNot(below | above, eq5F);
 398
 38515399                if (outside != Vector128<byte>.Zero)
 400                {
 30193401                    result = default;
 30193402                    return false;
 403                }
 404
 8322405                Vector128<byte> shift = SimdShuffle(lutShift.AsByte(), hiNibbles, mask8F);
 8322406                str += shift;
 407
 8322408                result = str + (eq5F & shiftForUnderscore);
 8322409                return true;
 410            }
 411
 412            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 413            [CompExactlyDependsOn(typeof(Avx2))]
 414            public bool TryDecode256Core(
 415                Vector256<sbyte> str,
 416                Vector256<sbyte> hiNibbles,
 417                Vector256<sbyte> maskSlashOrUnderscore,
 418                Vector256<sbyte> lutLow,
 419                Vector256<sbyte> lutHigh,
 420                Vector256<sbyte> lutShift,
 421                Vector256<sbyte> shiftForUnderscore,
 422                out Vector256<sbyte> result)
 423            {
 33185424                Vector256<sbyte> lowerBound = Avx2.Shuffle(lutLow, hiNibbles);
 33185425                Vector256<sbyte> upperBound = Avx2.Shuffle(lutHigh, hiNibbles);
 426
 33185427                Vector256<sbyte> below = Vector256.LessThan(str, lowerBound);
 33185428                Vector256<sbyte> above = Vector256.GreaterThan(str, upperBound);
 33185429                Vector256<sbyte> eq5F = Vector256.Equals(str, maskSlashOrUnderscore);
 430
 431                // Take care as arguments are flipped in order!
 33185432                Vector256<sbyte> outside = Vector256.AndNot(below | above, eq5F);
 433
 33185434                if (outside != Vector256<sbyte>.Zero)
 435                {
 29103436                    result = default;
 29103437                    return false;
 438                }
 439
 4082440                Vector256<sbyte> shift = Avx2.Shuffle(lutShift, hiNibbles);
 4082441                str += shift;
 442
 4082443                result = str + (eq5F & shiftForUnderscore);
 4082444                return true;
 445            }
 446
 447            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 448            public unsafe bool TryLoadVector512(byte* src, byte* srcStart, int sourceLength, out Vector512<sbyte> str) =
 36409449                default(Base64DecoderByte).TryLoadVector512(src, srcStart, sourceLength, out str);
 450
 451            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 452            [CompExactlyDependsOn(typeof(Avx2))]
 453            public unsafe bool TryLoadAvxVector256(byte* src, byte* srcStart, int sourceLength, out Vector256<sbyte> str
 31513454                default(Base64DecoderByte).TryLoadAvxVector256(src, srcStart, sourceLength, out str);
 455
 456            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 457            public unsafe bool TryLoadVector128(byte* src, byte* srcStart, int sourceLength, out Vector128<byte> str) =>
 36293458                default(Base64DecoderByte).TryLoadVector128(src, srcStart, sourceLength, out str);
 459
 460            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 461            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 462            public unsafe bool TryLoadArmVector128x4(byte* src, byte* srcStart, int sourceLength,
 463                out Vector128<byte> str1, out Vector128<byte> str2, out Vector128<byte> str3, out Vector128<byte> str4) 
 0464                default(Base64DecoderByte).TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out st
 465#endif // NET
 466
 467            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 468            public unsafe int DecodeFourElements(byte* source, ref sbyte decodingMap) =>
 105578469                default(Base64DecoderByte).DecodeFourElements(source, ref decodingMap);
 470
 471            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 472            public unsafe int DecodeRemaining(byte* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out uint
 2357473                default(Base64DecoderByte).DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3);
 474
 475            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30861476            public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan<byte> span) => default(Base64DecoderByte).IndexOfAnyExcep
 477
 478            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 479            public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper<TBase64Decoder>(TBase64Decoder decoder, ReadOnly
 480                ref int bytesConsumed, ref int bytesWritten, bool isFinalBlock = true) where TBase64Decoder : IBase64Dec
 2121481                DecodeWithWhiteSpaceBlockwise(decoder, utf8, bytes, ref bytesConsumed, ref bytesWritten, isFinalBlock);
 482        }
 483
 484        private readonly struct Base64UrlDecoderChar : IBase64Decoder<ushort>
 485        {
 3233486            public ReadOnlySpan<sbyte> DecodingMap => default(Base64UrlDecoderByte).DecodingMap;
 487
 1564488            public ReadOnlySpan<uint> VbmiLookup0 => default(Base64UrlDecoderByte).VbmiLookup0;
 489
 1564490            public ReadOnlySpan<uint> VbmiLookup1 => default(Base64UrlDecoderByte).VbmiLookup1;
 491
 1336492            public ReadOnlySpan<sbyte> Avx2LutHigh => default(Base64UrlDecoderByte).Avx2LutHigh;
 493
 1336494            public ReadOnlySpan<sbyte> Avx2LutLow => default(Base64UrlDecoderByte).Avx2LutLow;
 495
 1336496            public ReadOnlySpan<sbyte> Avx2LutShift => default(Base64UrlDecoderByte).Avx2LutShift;
 497
 3030498            public byte MaskSlashOrUnderscore => default(Base64UrlDecoderByte).MaskSlashOrUnderscore;
 499
 1694500            public ReadOnlySpan<int> Vector128LutHigh => default(Base64UrlDecoderByte).Vector128LutHigh;
 501
 1694502            public ReadOnlySpan<int> Vector128LutLow => default(Base64UrlDecoderByte).Vector128LutLow;
 503
 1694504            public ReadOnlySpan<uint> Vector128LutShift => default(Base64UrlDecoderByte).Vector128LutShift;
 505
 0506            public ReadOnlySpan<uint> AdvSimdLutOne3 => default(Base64UrlDecoderByte).AdvSimdLutOne3;
 507
 0508            public uint AdvSimdLutTwo3Uint1 => default(Base64UrlDecoderByte).AdvSimdLutTwo3Uint1;
 509
 3233510            public int GetMaxDecodedLength(int sourceLength) => default(Base64UrlDecoderByte).GetMaxDecodedLength(source
 511
 0512            public bool IsInvalidLength(int bufferLength) => default(Base64UrlDecoderByte).IsInvalidLength(bufferLength)
 513
 2694514            public bool IsValidPadding(uint padChar) => default(Base64UrlDecoderByte).IsValidPadding(padChar);
 515
 3233516            public int SrcLength(bool isFinalBlock, int sourceLength) => default(Base64UrlDecoderByte).SrcLength(isFinal
 517
 518#if NET
 519            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 520            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 521            [CompExactlyDependsOn(typeof(Ssse3))]
 522            public bool TryDecode128Core(Vector128<byte> str, Vector128<byte> hiNibbles, Vector128<byte> maskSlashOrUnde
 523                Vector128<byte> lutLow, Vector128<byte> lutHigh, Vector128<sbyte> lutShift, Vector128<byte> shiftForUnde
 2222524                default(Base64UrlDecoderByte).TryDecode128Core(str, hiNibbles, maskSlashOrUnderscore, mask8F, lutLow, lu
 525
 526            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 527            [CompExactlyDependsOn(typeof(Avx2))]
 528            public bool TryDecode256Core(Vector256<sbyte> str, Vector256<sbyte> hiNibbles, Vector256<sbyte> maskSlashOrU
 529                Vector256<sbyte> lutHigh, Vector256<sbyte> lutShift, Vector256<sbyte> shiftForUnderscore, out Vector256<
 1672530                default(Base64UrlDecoderByte).TryDecode256Core(str, hiNibbles, maskSlashOrUnderscore, lutLow, lutHigh, l
 531
 532            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 533            public unsafe bool TryLoadVector512(ushort* src, ushort* srcStart, int sourceLength, out Vector512<sbyte> st
 17316534                default(Base64DecoderChar).TryLoadVector512(src, srcStart, sourceLength, out str);
 535
 536            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 537            [CompExactlyDependsOn(typeof(Avx2))]
 538            public unsafe bool TryLoadAvxVector256(ushort* src, ushort* srcStart, int sourceLength, out Vector256<sbyte>
 1672539                default(Base64DecoderChar).TryLoadAvxVector256(src, srcStart, sourceLength, out str);
 540
 541            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 542            public unsafe bool TryLoadVector128(ushort* src, ushort* srcStart, int sourceLength, out Vector128<byte> str
 2222543                default(Base64DecoderChar).TryLoadVector128(src, srcStart, sourceLength, out str);
 544
 545            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 546            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 547            public unsafe bool TryLoadArmVector128x4(ushort* src, ushort* srcStart, int sourceLength,
 548                out Vector128<byte> str1, out Vector128<byte> str2, out Vector128<byte> str3, out Vector128<byte> str4) 
 0549                default(Base64DecoderChar).TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out st
 550#endif // NET
 551
 552            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 553            public unsafe int DecodeFourElements(ushort* source, ref sbyte decodingMap) =>
 8950554                default(Base64DecoderChar).DecodeFourElements(source, ref decodingMap);
 555
 556            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 557            public unsafe int DecodeRemaining(ushort* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out ui
 1638558                default(Base64DecoderChar).DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3);
 559
 560            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 0561            public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan<ushort> span) => default(Base64DecoderChar).IndexOfAnyExc
 562
 563            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 564            public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper<TBase64Decoder>(TBase64Decoder decoder, ReadOnly
 565                ref int bytesConsumed, ref int bytesWritten, bool isFinalBlock = true) where TBase64Decoder : IBase64Dec
 0566                DecodeWithWhiteSpaceBlockwise(decoder, source, bytes, ref bytesConsumed, ref bytesWritten, isFinalBlock)
 567        }
 568    }
 569}
 570

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Runtime.CompilerServices;
 7using System.Runtime.InteropServices;
 8#if NET
 9using System.Runtime.Intrinsics;
 10using System.Runtime.Intrinsics.Arm;
 11using System.Runtime.Intrinsics.X86;
 12#endif
 13using static System.Buffers.Text.Base64Helper;
 14
 15namespace System.Buffers.Text
 16{
 17    public static partial class Base64Url
 18    {
 19        /// <summary>
 20        /// Encodes the span of binary data into UTF-8 encoded text represented as Base64Url.
 21        /// </summary>
 22        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 23        /// <param name="destination">The output span which contains the result of the operation, i.e. the UTF-8 encoded
 24        /// <param name="bytesConsumed">When this method returns, contains the number of input bytes consumed during the
 25        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 26        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to encod
 27        /// such as when calling in a loop, subsequent calls with <see langword="false"/> should end with <see langword=
 28        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 29        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 30        public static OperationStatus EncodeToUtf8(ReadOnlySpan<byte> source,
 31            Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true) =>
 032            EncodeTo(default(Base64UrlEncoderByte), source, destination, out bytesConsumed, out bytesWritten, isFinalBlo
 33
 34        /// <summary>
 35        /// Returns the number of characters required to encode
 36        /// <paramref name="bytesLength"/> bytes to Base64Url.
 37        /// </summary>
 38        /// <remarks>
 39        /// Because the Base64Url characters are all in the 7-bit ASCII range,
 40        /// the number of characters is equal both to the number of
 41        /// <see cref="char"/> values written by methods like
 42        /// <see cref="EncodeToChars(ReadOnlySpan{byte}, Span{char})"/>
 43        /// and the number of <see cref="byte"/> values written by UTF-8 methods like
 44        /// <see cref="EncodeToUtf8(ReadOnlySpan{byte}, Span{byte})"/>.
 45        /// </remarks>
 46        /// <exception cref="ArgumentOutOfRangeException">
 47        /// <paramref name="bytesLength"/> is less than 0 or greater than 1610612733.
 48        /// </exception>
 49        public static int GetEncodedLength(int bytesLength)
 50        {
 51#if NET
 982852            ArgumentOutOfRangeException.ThrowIfGreaterThan<uint>((uint)bytesLength, MaximumEncodeLength);
 53
 982854            (uint whole, uint remainder) = uint.DivRem((uint)bytesLength, 3);
 55
 982856            return (int)(whole * 4 + (remainder > 0 ? remainder + 1 : 0)); // if remainder is 1 or 2, the encoded length
 57#else
 58            if ((uint)bytesLength > MaximumEncodeLength)
 59            {
 60                throw new ArgumentOutOfRangeException(nameof(bytesLength));
 61            }
 62
 63            int remainder = (int)((uint)bytesLength % 3);
 64
 65            return (bytesLength / 3) * 4 + (remainder > 0 ? remainder + 1 : 0);
 66#endif
 67        }
 68
 69        /// <summary>
 70        /// Encodes the span of binary data into UTF-8 encoded text represented as Base64Url.
 71        /// </summary>
 72        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 73        /// <param name="destination">The output span which contains the result of the operation, i.e. the UTF-8 encoded
 74        /// <returns>The number of bytes written into the destination span. This can be used to slice the output for sub
 75        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the en
 76        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 77        public static int EncodeToUtf8(ReadOnlySpan<byte> source, Span<byte> destination)
 78        {
 079            OperationStatus status = EncodeToUtf8(source, destination, out _, out int bytesWritten);
 80
 081            if (status == OperationStatus.Done)
 82            {
 083                return bytesWritten;
 84            }
 85
 086            Debug.Assert(status == OperationStatus.DestinationTooSmall);
 087            throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 88        }
 89
 90        /// <summary>
 91        /// Encodes the span of binary data into UTF-8 encoded text represented as Base64Url.
 92        /// </summary>
 93        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 94        /// <returns>The output byte array which contains the result of the operation, i.e. the UTF-8 encoded text in Ba
 95        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 96        public static byte[] EncodeToUtf8(ReadOnlySpan<byte> source)
 97        {
 098            byte[] destination = new byte[GetEncodedLength(source.Length)];
 099            EncodeToUtf8(source, destination, out _, out int bytesWritten);
 0100            Debug.Assert(destination.Length == bytesWritten);
 101
 0102            return destination;
 103        }
 104
 105        /// <summary>
 106        /// Encodes the span of binary data into unicode ASCII chars represented as Base64Url.
 107        /// </summary>
 108        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 109        /// <param name="destination">The output span which contains the result of the operation, i.e. the ASCII chars i
 110        /// <param name="bytesConsumed">When this method returns, contains the number of input bytes consumed during the
 111        /// <param name="charsWritten">When this method returns, contains the number of chars written into the output sp
 112        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to encod
 113        /// such as when calling in a loop, subsequent calls with <see langword="false"/> should end with <see langword=
 114        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 115        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 116        public static OperationStatus EncodeToChars(ReadOnlySpan<byte> source, Span<char> destination,
 117            out int bytesConsumed, out int charsWritten, bool isFinalBlock = true) =>
 4914118            EncodeTo(default(Base64UrlEncoderChar), source, MemoryMarshal.Cast<char, ushort>(destination), out bytesCons
 119
 120        /// <summary>
 121        /// Encodes the span of binary data into unicode ASCII chars represented as Base64Url.
 122        /// </summary>
 123        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 124        /// <param name="destination">The output span which contains the result of the operation, i.e. the ASCII chars i
 125        /// <returns>The number of chars written into the destination span. This can be used to slice the output for sub
 126        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the en
 127        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 128        public static int EncodeToChars(ReadOnlySpan<byte> source, Span<char> destination)
 129        {
 0130            OperationStatus status = EncodeToChars(source, destination, out _, out int charsWritten);
 131
 0132            if (status == OperationStatus.Done)
 133            {
 0134                return charsWritten;
 135            }
 136
 0137            Debug.Assert(status == OperationStatus.DestinationTooSmall);
 0138            throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 139        }
 140
 141        /// <summary>
 142        /// Encodes the span of binary data into unicode ASCII chars represented as Base64Url.
 143        /// </summary>
 144        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 145        /// <returns>A char array which contains the result of the operation, i.e. the ASCII chars in Base64Url.</return
 146        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 147        public static char[] EncodeToChars(ReadOnlySpan<byte> source)
 148        {
 0149            char[] destination = new char[GetEncodedLength(source.Length)];
 0150            EncodeToChars(source, destination, out _, out int charsWritten);
 0151            Debug.Assert(destination.Length == charsWritten);
 152
 0153            return destination;
 154        }
 155
 156        /// <summary>
 157        /// Encodes the span of binary data into unicode string represented as Base64Url ASCII chars.
 158        /// </summary>
 159        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 160        /// <returns>A string which contains the result of the operation, i.e. the ASCII string in Base64Url.</returns>
 161        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 162        public static unsafe string EncodeToString(ReadOnlySpan<byte> source)
 163        {
 164#if NET
 1638165            int encodedLength = GetEncodedLength(source.Length);
 166
 1638167            return string.Create(encodedLength, (IntPtr)(&source), static (buffer, spanPtr) =>
 1638168            {
 1638169                ReadOnlySpan<byte> source = *(ReadOnlySpan<byte>*)spanPtr;
 1638170                EncodeToChars(source, buffer, out _, out int charsWritten);
 1638171                Debug.Assert(buffer.Length == charsWritten, $"The source length: {source.Length}, bytes written: {charsW
 3276172            });
 173#else
 174            char[] destination = new char[GetEncodedLength(source.Length)];
 175            EncodeToChars(source, destination, out _, out int charsWritten);
 176            Debug.Assert(destination.Length == charsWritten);
 177
 178            return new string(destination);
 179#endif
 180        }
 181
 182        /// <summary>
 183        /// Encodes the span of binary data into unicode ASCII chars represented as Base64Url.
 184        /// </summary>
 185        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 186        /// <param name="destination">The output span which contains the result of the operation, i.e. the ASCII chars i
 187        /// <param name="charsWritten">When this method returns, contains the number of chars written into the output sp
 188        /// <returns><see langword="true"/> if chars encoded successfully, otherwise <see langword="false"/>.</returns>
 189        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 190        public static bool TryEncodeToChars(ReadOnlySpan<byte> source, Span<char> destination, out int charsWritten)
 191        {
 0192            OperationStatus status = EncodeToChars(source, destination, out _, out charsWritten);
 193
 0194            return status == OperationStatus.Done;
 195        }
 196
 197        /// <summary>
 198        /// Encodes the span of binary data into UTF-8 encoded text represented as Base64Url.
 199        /// </summary>
 200        /// <param name="source">The input span which contains binary data that needs to be encoded.</param>
 201        /// <param name="destination">The output span which contains the result of the operation, i.e. the UTF-8 encoded
 202        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 203        /// <returns><see langword="true"/> if bytes encoded successfully, otherwise <see langword="false"/>.</returns>
 204        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 205        public static bool TryEncodeToUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
 206        {
 0207            OperationStatus status = EncodeToUtf8(source, destination, out _, out bytesWritten);
 208
 0209            return status == OperationStatus.Done;
 210        }
 211
 212        /// <summary>
 213        /// Encodes the span of binary data (in-place) into UTF-8 encoded text represented as Base64Url.
 214        /// The encoded text output is larger than the binary data contained in the input (the operation inflates the da
 215        /// </summary>
 216        /// <param name="buffer">The input span which contains binary data that needs to be encoded.
 217        /// It needs to be large enough to fit the result of the operation.</param>
 218        /// <param name="dataLength">The amount of binary data contained within the buffer that needs to be encoded
 219        /// (and needs to be smaller than the buffer length).</param>
 220        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the buffer. T
 221        /// <returns><see langword="true"/> if bytes encoded successfully, otherwise <see langword="false"/>.</returns>
 222        /// <remarks>This implementation of the base64url encoding omits the optional padding characters.</remarks>
 223        public static bool TryEncodeToUtf8InPlace(Span<byte> buffer, int dataLength, out int bytesWritten)
 224        {
 1638225            OperationStatus status = EncodeToUtf8InPlace(default(Base64UrlEncoderByte), buffer, dataLength, out bytesWri
 226
 1638227            return status == OperationStatus.Done;
 228        }
 229
 230        private readonly struct Base64UrlEncoderByte : Base64Helper.IBase64Encoder<byte>
 231        {
 8938232            public ReadOnlySpan<byte> EncodingMap => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"u
 233
 4104234            public sbyte Avx2LutChar62 => -17;  // char '-' diff
 235
 4104236            public sbyte Avx2LutChar63 => 32;   // char '_' diff
 237
 0238            public ReadOnlySpan<byte> AdvSimdLut4 => "wxyz0123456789-_"u8;
 239
 2157240            public uint Ssse3AdvSimdLutE3 => 0x000020EF;
 241
 1226242            public int IncrementPadTwo => 2;
 243
 886244            public int IncrementPadOne => 3;
 245
 246            public int GetMaxSrcLength(int srcLength, int destLength) =>
 4914247                srcLength <= MaximumEncodeLength && destLength >= GetEncodedLength(srcLength) ?
 4914248                srcLength : GetMaxDecodedLength(destLength);
 249
 250            public uint GetInPlaceDestinationLength(int encodedLength, int leftOver) =>
 1638251                leftOver > 0 ? (uint)(encodedLength - leftOver - 1) : (uint)(encodedLength - 4);
 252
 1638253            public int GetMaxEncodedLength(int srcLength) => GetEncodedLength(srcLength);
 254
 255            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 256            public unsafe void EncodeOneOptionallyPadTwo(byte* oneByte, byte* dest, ref byte encodingMap)
 257            {
 258                uint t0 = oneByte[0];
 259
 613260                uint i = t0 << 8;
 261
 613262                byte i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 10));
 613263                byte i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 4) & 0x3F));
 264
 265                ushort result;
 266
 613267                if (BitConverter.IsLittleEndian)
 268                {
 613269                    result = (ushort)(i0 | (i1 << 8));
 270                }
 271                else
 272                {
 273                    result = (ushort)((i0 << 8) | i1);
 274                }
 275
 613276                Unsafe.WriteUnaligned(dest, result);
 613277            }
 278
 279            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 280            public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, byte* dest, ref byte encodingMap)
 281            {
 443282                uint t0 = twoBytes[0];
 443283                uint t1 = twoBytes[1];
 284
 443285                uint i = (t0 << 16) | (t1 << 8);
 286
 443287                byte i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 18));
 443288                byte i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 12) & 0x3F));
 443289                byte i2 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 6) & 0x3F));
 290
 443291                dest[0] = i0;
 443292                dest[1] = i1;
 443293                dest[2] = i2;
 443294            }
 295
 296#if NET
 297            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 298            public unsafe void StoreVector512ToDestination(byte* dest, byte* destStart, int destLength, Vector512<byte> 
 0299                default(Base64EncoderByte).StoreVector512ToDestination(dest, destStart, destLength, str);
 300
 301            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 302            [CompExactlyDependsOn(typeof(Avx2))]
 303            public unsafe void StoreVector256ToDestination(byte* dest, byte* destStart, int destLength, Vector256<byte> 
 0304                default(Base64EncoderByte).StoreVector256ToDestination(dest, destStart, destLength, str);
 305
 306            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 307            public unsafe void StoreVector128ToDestination(byte* dest, byte* destStart, int destLength, Vector128<byte> 
 0308                default(Base64EncoderByte).StoreVector128ToDestination(dest, destStart, destLength, str);
 309
 310            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 311            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 312            public unsafe void StoreArmVector128x4ToDestination(byte* dest, byte* destStart, int destLength,
 313                Vector128<byte> res1, Vector128<byte> res2, Vector128<byte> res3, Vector128<byte> res4) =>
 0314                default(Base64EncoderByte).StoreArmVector128x4ToDestination(dest, destStart, destLength, res1, res2, res
 315#endif // NET
 316
 317            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 318            public unsafe void EncodeThreeAndWrite(byte* threeBytes, byte* destination, ref byte encodingMap) =>
 0319                default(Base64EncoderByte).EncodeThreeAndWrite(threeBytes, destination, ref encodingMap);
 320        }
 321
 322        private readonly struct Base64UrlEncoderChar : IBase64Encoder<ushort>
 323        {
 7299324            public ReadOnlySpan<byte> EncodingMap => default(Base64UrlEncoderByte).EncodingMap;
 325
 4104326            public sbyte Avx2LutChar62 => default(Base64UrlEncoderByte).Avx2LutChar62;
 327
 4104328            public sbyte Avx2LutChar63 => default(Base64UrlEncoderByte).Avx2LutChar63;
 329
 0330            public ReadOnlySpan<byte> AdvSimdLut4 => default(Base64UrlEncoderByte).AdvSimdLut4;
 331
 2157332            public uint Ssse3AdvSimdLutE3 => default(Base64UrlEncoderByte).Ssse3AdvSimdLutE3;
 333
 1226334            public int IncrementPadTwo => default(Base64UrlEncoderByte).IncrementPadTwo;
 335
 886336            public int IncrementPadOne => default(Base64UrlEncoderByte).IncrementPadOne;
 337
 338            public int GetMaxSrcLength(int srcLength, int destLength) =>
 4914339                default(Base64UrlEncoderByte).GetMaxSrcLength(srcLength, destLength);
 340
 0341            public uint GetInPlaceDestinationLength(int encodedLength, int _) => 0; // not used for char encoding
 342
 0343            public int GetMaxEncodedLength(int _) => 0;  // not used for char encoding
 344
 345            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 346            public unsafe void EncodeOneOptionallyPadTwo(byte* oneByte, ushort* dest, ref byte encodingMap) =>
 1226347                Base64Helper.EncodeOneOptionallyPadTwo(oneByte, dest, ref encodingMap);
 348
 349            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 350            public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, ushort* dest, ref byte encodingMap) =>
 886351                Base64Helper.EncodeTwoOptionallyPadOne(twoBytes, dest, ref encodingMap);
 352
 353#if NET
 354            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 355            public unsafe void StoreVector512ToDestination(ushort* dest, ushort* destStart, int destLength, Vector512<by
 26145356                default(Base64EncoderChar).StoreVector512ToDestination(dest, destStart, destLength, str);
 357
 358            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 359            public unsafe void StoreVector256ToDestination(ushort* dest, ushort* destStart, int destLength, Vector256<by
 2925360                default(Base64EncoderChar).StoreVector256ToDestination(dest, destStart, destLength, str);
 361
 362            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 363            public unsafe void StoreVector128ToDestination(ushort* dest, ushort* destStart, int destLength, Vector128<by
 2457364                default(Base64EncoderChar).StoreVector128ToDestination(dest, destStart, destLength, str);
 365
 366            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 367            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 368            public unsafe void StoreArmVector128x4ToDestination(ushort* dest, ushort* destStart, int destLength,
 369                Vector128<byte> res1, Vector128<byte> res2, Vector128<byte> res3, Vector128<byte> res4) =>
 0370                default(Base64EncoderChar).StoreArmVector128x4ToDestination(dest, destStart, destLength, res1, res2, res
 371#endif // NET
 372
 373            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 374            public unsafe void EncodeThreeAndWrite(byte* threeBytes, ushort* destination, ref byte encodingMap) =>
 11730375                default(Base64EncoderChar).EncodeThreeAndWrite(threeBytes, destination, ref encodingMap);
 376        }
 377    }
 378}
 379

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Runtime.CompilerServices;
 6
 7namespace System.Buffers.Text
 8{
 9    public static partial class Base64Url
 10    {
 11        /// <summary>Validates that the specified span of text is comprised of valid Base64Url-encoded data.</summary>
 12        /// <param name="base64UrlText">A span of text to validate.</param>
 13        /// <returns><see langword="true"/> if <paramref name="base64UrlText"/> contains a valid, decodable sequence of 
 14        /// <remarks>
 15        /// If the method returns <see langword="true"/>, the same text passed to <see cref="Base64Url.DecodeFromChars(R
 16        /// <see cref="Base64Url.TryDecodeFromChars(ReadOnlySpan{char}, Span{byte}, out int)"/> would successfully decod
 17        /// of <see cref="Base64Url.TryDecodeFromChars(ReadOnlySpan{char}, Span{byte}, out int)"/> assuming sufficient o
 18        /// Any amount of whitespace is allowed anywhere in the input, where whitespace is defined as the characters ' '
 19        /// </remarks>
 20        public static bool IsValid(ReadOnlySpan<char> base64UrlText) =>
 021            Base64Helper.IsValid(default(Base64UrlCharValidatable), base64UrlText, out _);
 22
 23        /// <summary>Validates that the specified span of text is comprised of valid Base64Url-encoded data.</summary>
 24        /// <param name="base64UrlText">A span of text to validate.</param>
 25        /// <param name="decodedLength">If the method returns true, the number of decoded bytes that will result from de
 26        /// <returns><see langword="true"/> if <paramref name="base64UrlText"/> contains a valid, decodable sequence of 
 27        /// <remarks>
 28        /// If the method returns <see langword="true"/>, the same text passed to <see cref="Base64Url.DecodeFromChars(R
 29        /// <see cref="Base64Url.TryDecodeFromChars(ReadOnlySpan{char}, Span{byte}, out int)"/> would successfully decod
 30        /// of <see cref="Base64Url.TryDecodeFromChars(ReadOnlySpan{char}, Span{byte}, out int)"/> assuming sufficient o
 31        /// Any amount of whitespace is allowed anywhere in the input, where whitespace is defined as the characters ' '
 32        /// </remarks>
 33        public static bool IsValid(ReadOnlySpan<char> base64UrlText, out int decodedLength) =>
 034            Base64Helper.IsValid(default(Base64UrlCharValidatable), base64UrlText, out decodedLength);
 35
 36        /// <summary>Validates that the specified span of UTF-8 text is comprised of valid Base64Url-encoded data.</summ
 37        /// <param name="utf8Base64UrlText">A span of UTF-8 text to validate.</param>
 38        /// <returns><see langword="true"/> if <paramref name="utf8Base64UrlText"/> contains a valid, decodable sequence
 39        /// <remarks>
 40        /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes).
 41        /// </remarks>
 42        public static bool IsValid(ReadOnlySpan<byte> utf8Base64UrlText) =>
 043            Base64Helper.IsValid(default(Base64UrlByteValidatable), utf8Base64UrlText, out _);
 44
 45        /// <summary>Validates that the specified span of UTF-8 text is comprised of valid Base64Url-encoded data.</summ
 46        /// <param name="utf8Base64UrlText">A span of UTF-8 text to validate.</param>
 47        /// <param name="decodedLength">If the method returns true, the number of decoded bytes that will result from de
 48        /// <returns><see langword="true"/> if <paramref name="utf8Base64UrlText"/> contains a valid, decodable sequence
 49        /// <remarks>
 50        /// where whitespace is defined as the characters ' ', '\t', '\r', or '\n' (as bytes).
 51        /// </remarks>
 52        public static bool IsValid(ReadOnlySpan<byte> utf8Base64UrlText, out int decodedLength) =>
 163853            Base64Helper.IsValid(default(Base64UrlByteValidatable), utf8Base64UrlText, out decodedLength);
 54
 55        private const uint UrlEncodingPad = '%'; // allowed for url padding
 56
 57        private readonly struct Base64UrlCharValidatable : Base64Helper.IBase64Validatable<char>
 58        {
 59#if NET
 060            private static readonly SearchValues<char> s_validBase64UrlChars = SearchValues.Create("ABCDEFGHIJKLMNOPQRST
 61
 062            public int IndexOfAnyExcept(ReadOnlySpan<char> span) => span.IndexOfAnyExcept(s_validBase64UrlChars);
 63#else
 64            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65            public int DecodeValue(char value)
 66            {
 67                if (value > byte.MaxValue)
 68                {
 69                    // Invalid char was found.
 70                    return -2;
 71                }
 72
 73                return default(Base64UrlDecoderByte).DecodingMap[value];
 74            }
 75#endif
 076            public bool IsWhiteSpace(char value) => Base64Helper.IsWhiteSpace(value);
 077            public bool IsEncodingPad(char value) => value == Base64Helper.EncodingPad || value == UrlEncodingPad;
 78            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 79            public bool ValidateAndDecodeLength(char lastChar, int length, int paddingCount, out int decodedLength) =>
 080                default(Base64UrlByteValidatable).ValidateAndDecodeLength((byte)lastChar, length, paddingCount, out deco
 81        }
 82
 83        private readonly struct Base64UrlByteValidatable : Base64Helper.IBase64Validatable<byte>
 84        {
 85#if NET
 186            private static readonly SearchValues<byte> s_validBase64UrlChars = SearchValues.Create(default(Base64UrlEnco
 87
 3299588            public int IndexOfAnyExcept(ReadOnlySpan<byte> span) => span.IndexOfAnyExcept(s_validBase64UrlChars);
 89#else
 90            public int DecodeValue(byte value) => default(Base64UrlDecoderByte).DecodingMap[value];
 91#endif
 7585492            public bool IsWhiteSpace(byte value) => Base64Helper.IsWhiteSpace(value);
 373193            public bool IsEncodingPad(byte value) => value == Base64Helper.EncodingPad || value == UrlEncodingPad;
 94            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 95            public bool ValidateAndDecodeLength(byte lastChar, int length, int paddingCount, out int decodedLength)
 96            {
 97                // Padding is optional for Base64Url, so need to account remainder.
 103598                int remainder = (int)((uint)length % 4);
 99
 1035100                if (paddingCount != 0)
 101                {
 123102                    length -= paddingCount;
 123103                    remainder = (int)((uint)length % 4);
 104
 105                    // if there is a padding, there should be remainder and the sum of remainder and padding should not 
 123106                    if (remainder == 0 || remainder + paddingCount > 4)
 107                    {
 36108                        decodedLength = 0;
 36109                        return false;
 110                    }
 111                }
 112
 999113                decodedLength = (length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0);
 114
 999115                if (remainder > 0)
 116                {
 658117                    int decoded = default(Base64UrlDecoderByte).DecodingMap[lastChar];
 118                    switch (remainder)
 119                    {
 82120                        case 1: return false; // 1 byte is not decodable => invalid.
 325121                        case 2: return ((decoded & 0x0F) == 0); // if unused lower 4 bits are set to 0
 251122                        case 3: return ((decoded & 0x03) == 0); // if unused lower 2 bits are set to 0
 123                    }
 124                }
 125
 341126                return true;
 127            }
 128        }
 129    }
 130}
 131

Methods/Properties

GetMaxDecodedLength(System.Int32)
DecodeFromUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
DecodeFromUtf8InPlace(System.Span`1<System.Byte>)
DecodeFromUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>)
TryDecodeFromUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&)
DecodeFromUtf8(System.ReadOnlySpan`1<System.Byte>)
DecodeFromChars(System.ReadOnlySpan`1<System.Char>,System.Span`1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
DecodeFromChars(System.ReadOnlySpan`1<System.Char>,System.Span`1<System.Byte>)
TryDecodeFromChars(System.ReadOnlySpan`1<System.Char>,System.Span`1<System.Byte>,System.Int32&)
DecodeFromChars(System.ReadOnlySpan`1<System.Char>)
DecodingMap()
VbmiLookup0()
VbmiLookup1()
Avx2LutHigh()
Avx2LutLow()
Avx2LutShift()
MaskSlashOrUnderscore()
Vector128LutHigh()
Vector128LutLow()
Vector128LutShift()
AdvSimdLutOne3()
AdvSimdLutTwo3Uint1()
GetMaxDecodedLength(System.Int32)
IsInvalidLength(System.Int32)
IsValidPadding(System.UInt32)
SrcLength(System.Boolean,System.Int32)
TryDecode128Core(System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.SByte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
TryDecode256Core(System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>&)
TryLoadVector512(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector512`1<System.SByte>&)
TryLoadAvxVector256(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector256`1<System.SByte>&)
TryLoadVector128(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
TryLoadArmVector128x4(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
DecodeFourElements(System.Byte*,System.SByte&)
DecodeRemaining(System.Byte*,System.SByte&,System.Int64,System.UInt32&,System.UInt32&)
IndexOfAnyExceptWhiteSpace(System.ReadOnlySpan`1<System.Byte>)
DecodeWithWhiteSpaceBlockwiseWrapper(TBase64Decoder,System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
DecodingMap()
VbmiLookup0()
VbmiLookup1()
Avx2LutHigh()
Avx2LutLow()
Avx2LutShift()
MaskSlashOrUnderscore()
Vector128LutHigh()
Vector128LutLow()
Vector128LutShift()
AdvSimdLutOne3()
AdvSimdLutTwo3Uint1()
GetMaxDecodedLength(System.Int32)
IsInvalidLength(System.Int32)
IsValidPadding(System.UInt32)
SrcLength(System.Boolean,System.Int32)
TryDecode128Core(System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.SByte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
TryDecode256Core(System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>,System.Runtime.Intrinsics.Vector256`1<System.SByte>&)
TryLoadVector512(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector512`1<System.SByte>&)
TryLoadAvxVector256(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector256`1<System.SByte>&)
TryLoadVector128(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
TryLoadArmVector128x4(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&,System.Runtime.Intrinsics.Vector128`1<System.Byte>&)
DecodeFourElements(System.UInt16*,System.SByte&)
DecodeRemaining(System.UInt16*,System.SByte&,System.Int64,System.UInt32&,System.UInt32&)
IndexOfAnyExceptWhiteSpace(System.ReadOnlySpan`1<System.UInt16>)
DecodeWithWhiteSpaceBlockwiseWrapper(TBase64Decoder,System.ReadOnlySpan`1<System.UInt16>,System.Span`1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
EncodeToUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
GetEncodedLength(System.Int32)
EncodeToUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>)
EncodeToUtf8(System.ReadOnlySpan`1<System.Byte>)
EncodeToChars(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>,System.Int32&,System.Int32&,System.Boolean)
EncodeToChars(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>)
EncodeToChars(System.ReadOnlySpan`1<System.Byte>)
EncodeToString(System.ReadOnlySpan`1<System.Byte>)
TryEncodeToChars(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>,System.Int32&)
TryEncodeToUtf8(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&)
TryEncodeToUtf8InPlace(System.Span`1<System.Byte>,System.Int32,System.Int32&)
EncodingMap()
Avx2LutChar62()
Avx2LutChar63()
AdvSimdLut4()
Ssse3AdvSimdLutE3()
IncrementPadTwo()
IncrementPadOne()
GetMaxSrcLength(System.Int32,System.Int32)
GetInPlaceDestinationLength(System.Int32,System.Int32)
GetMaxEncodedLength(System.Int32)
EncodeOneOptionallyPadTwo(System.Byte*,System.Byte*,System.Byte&)
EncodeTwoOptionallyPadOne(System.Byte*,System.Byte*,System.Byte&)
StoreVector512ToDestination(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector512`1<System.Byte>)
StoreVector256ToDestination(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector256`1<System.Byte>)
StoreVector128ToDestination(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>)
StoreArmVector128x4ToDestination(System.Byte*,System.Byte*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>)
EncodeThreeAndWrite(System.Byte*,System.Byte*,System.Byte&)
EncodingMap()
Avx2LutChar62()
Avx2LutChar63()
AdvSimdLut4()
Ssse3AdvSimdLutE3()
IncrementPadTwo()
IncrementPadOne()
GetMaxSrcLength(System.Int32,System.Int32)
GetInPlaceDestinationLength(System.Int32,System.Int32)
GetMaxEncodedLength(System.Int32)
EncodeOneOptionallyPadTwo(System.Byte*,System.UInt16*,System.Byte&)
EncodeTwoOptionallyPadOne(System.Byte*,System.UInt16*,System.Byte&)
StoreVector512ToDestination(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector512`1<System.Byte>)
StoreVector256ToDestination(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector256`1<System.Byte>)
StoreVector128ToDestination(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>)
StoreArmVector128x4ToDestination(System.UInt16*,System.UInt16*,System.Int32,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>,System.Runtime.Intrinsics.Vector128`1<System.Byte>)
EncodeThreeAndWrite(System.Byte*,System.UInt16*,System.Byte&)
IsValid(System.ReadOnlySpan`1<System.Char>)
IsValid(System.ReadOnlySpan`1<System.Char>,System.Int32&)
IsValid(System.ReadOnlySpan`1<System.Byte>)
IsValid(System.ReadOnlySpan`1<System.Byte>,System.Int32&)
.cctor()
IndexOfAnyExcept(System.ReadOnlySpan`1<System.Char>)
IsWhiteSpace(System.Char)
IsEncodingPad(System.Char)
ValidateAndDecodeLength(System.Char,System.Int32,System.Int32,System.Int32&)
.cctor()
IndexOfAnyExcept(System.ReadOnlySpan`1<System.Byte>)
IsWhiteSpace(System.Byte)
IsEncodingPad(System.Byte)
ValidateAndDecodeLength(System.Byte,System.Int32,System.Int32,System.Int32&)