< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 298
Coverable lines: 298
Total lines: 1083
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 72
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: GetMaxDecodedLength(...)0%220%
File 1: DecodeFromUtf8(...)100%110%
File 1: DecodeFromUtf8InPlace(...)0%220%
File 1: DecodeFromUtf8(...)0%440%
File 1: TryDecodeFromUtf8(...)0%440%
File 1: DecodeFromUtf8(...)0%880%
File 1: DecodeFromChars(...)100%110%
File 1: DecodeFromChars(...)0%440%
File 1: TryDecodeFromChars(...)0%220%
File 1: DecodeFromChars(...)0%660%
File 1: GetMaxDecodedLength(...)100%110%
File 1: IsInvalidLength(...)100%110%
File 1: IsValidPadding(...)0%220%
File 1: SrcLength(...)0%220%
File 1: TryDecode128Core(...)0%220%
File 1: TryDecode256Core(...)0%220%
File 1: TryLoadVector512(...)100%110%
File 1: TryLoadAvxVector256(...)100%110%
File 1: TryLoadVector128(...)100%110%
File 1: TryLoadArmVector128x4(...)100%110%
File 1: DecodeFourElements(...)100%110%
File 1: DecodeRemaining(...)100%110%
File 1: IndexOfAnyExceptWhiteSpace(...)100%110%
File 1: DecodeWithWhiteSpaceBlockwiseWrapper(...)100%110%
File 1: GetMaxDecodedLength(...)100%110%
File 1: IsInvalidLength(...)100%110%
File 1: IsValidPadding(...)100%110%
File 1: SrcLength(...)100%110%
File 1: TryDecode128Core(...)100%110%
File 1: TryDecode256Core(...)100%110%
File 1: TryLoadVector512(...)100%110%
File 1: TryLoadAvxVector256(...)100%110%
File 1: TryLoadVector128(...)100%110%
File 1: TryLoadArmVector128x4(...)100%110%
File 1: DecodeFourElements(...)100%110%
File 1: DecodeRemaining(...)100%110%
File 1: IndexOfAnyExceptWhiteSpace(...)100%110%
File 1: DecodeWithWhiteSpaceBlockwiseWrapper(...)100%110%
File 2: EncodeToUtf8(...)100%110%
File 2: GetEncodedLength(...)0%220%
File 2: EncodeToUtf8(...)0%220%
File 2: EncodeToUtf8(...)100%110%
File 2: EncodeToChars(...)100%110%
File 2: EncodeToChars(...)0%220%
File 2: EncodeToChars(...)100%110%
File 2: EncodeToString(...)0%220%
File 2: TryEncodeToChars(...)100%110%
File 2: TryEncodeToUtf8(...)100%110%
File 2: TryEncodeToUtf8InPlace(...)100%110%
File 2: GetMaxSrcLength(...)0%440%
File 2: GetInPlaceDestinationLength(...)0%220%
File 2: GetMaxEncodedLength(...)100%110%
File 2: EncodeOneOptionallyPadTwo(...)100%110%
File 2: EncodeTwoOptionallyPadOne(...)100%110%
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%110%
File 2: GetInPlaceDestinationLength(...)100%110%
File 2: GetMaxEncodedLength(...)100%110%
File 2: EncodeOneOptionallyPadTwo(...)100%110%
File 2: EncodeTwoOptionallyPadOne(...)100%110%
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 3: IsValid(...)100%110%
File 3: IsValid(...)100%110%
File 3: IsValid(...)100%110%
File 3: IsValid(...)100%110%
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%110%
File 3: IndexOfAnyExcept(...)100%110%
File 3: IsWhiteSpace(...)100%110%
File 3: IsEncodingPad(...)0%220%
File 3: ValidateAndDecodeLength(...)0%14140%

File(s)

D:\runner\runtime\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;
 7using System.Runtime.CompilerServices;
 8using System.Runtime.InteropServices;
 9#if NET
 10using System.Runtime.Intrinsics;
 11using System.Runtime.Intrinsics.Arm;
 12using System.Runtime.Intrinsics.Wasm;
 13using System.Runtime.Intrinsics.X86;
 14#endif
 15using static System.Buffers.Text.Base64Helper;
 16
 17namespace System.Buffers.Text
 18{
 19    // AVX2 and Vector128 version based on https://github.com/gfoidl/Base64/blob/5383320e28cac6c7ac6f86502fb05d23a048a21
 20#pragma warning disable 1591 // TODO: Document this API. https://github.com/dotnet/runtime/issues/105974
 21    public static partial class Base64Url
 22#pragma warning restore 1591
 23    {
 24        private const int MaxStackallocThreshold = 256;
 25
 26        /// <summary>
 27        /// Returns the maximum length (in bytes) of the result if you were to decode Base64Url-encoded text from a span
 28        /// </summary>
 29        /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="base64Length"/> is less than 0.
 30        /// </exception>
 31        public static int GetMaxDecodedLength(int base64Length)
 32        {
 33#if NET
 034            ArgumentOutOfRangeException.ThrowIfNegative(base64Length);
 35
 036            (uint whole, uint remainder) = uint.DivRem((uint)base64Length, 4);
 37
 038            return (int)(whole * 3 + (remainder > 0 ? remainder - 1 : 0));
 39#else
 40            if (base64Length < 0)
 41            {
 42                throw new ArgumentOutOfRangeException(nameof(base64Length));
 43            }
 44
 45            int remainder = (int)((uint)base64Length % 4);
 46
 47            return (base64Length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0);
 48#endif
 49        }
 50
 51        /// <summary>
 52        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 53        /// </summary>
 54        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 55        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 56        /// <param name="bytesConsumed">When this method returns, contains the number of input bytes consumed during the
 57        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 58        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to decod
 59        /// such as when calling in a loop. Calls with <see langword="false"/> should be followed up with another call w
 60        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 61        /// <remarks>
 62        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 63        /// If the <paramref name="source"/> length is not a multiple of 4 and <paramref name="isFinalBlock"/> is <see l
 64        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 65        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 66        /// - Remainder of 1 byte - will cause OperationStatus.InvalidData result.
 67        /// </remarks>
 68        public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesCon
 069            DecodeFrom(default(Base64UrlDecoderByte), source, destination, out bytesConsumed, out bytesWritten, isFinalB
 70
 71        /// <summary>
 72        /// Decodes the span of UTF-8 encoded text in Base64Url into binary data, in-place.
 73        /// The decoded binary output is smaller than the text data contained in the input (the operation deflates the d
 74        /// </summary>
 75        /// <param name="buffer">The input span which contains the Base64Url text data that needs to be decoded.</param>
 76        /// <returns>The number of bytes written into <paramref name="buffer"/>. This can be used to slice the output fo
 77        /// <exception cref="FormatException"><paramref name="buffer"/> contains an invalid Base64Url character,
 78        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 79        /// <remarks>
 80        /// As padding is optional for Base64Url the <paramref name="buffer"/> length not required to be a multiple of 4
 81        /// If the <paramref name="buffer"/> length is not a multiple of 4 the remainders decoded accordingly:
 82        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 83        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 84        /// - Remainder of 1 byte - is invalid input, causes FormatException.
 85        /// </remarks>
 86        public static int DecodeFromUtf8InPlace(Span<byte> buffer)
 87        {
 088            OperationStatus status = DecodeFromUtf8InPlace<Base64UrlDecoderByte>(default, buffer, out int bytesWritten, 
 89
 90            // Base64.DecodeFromUtf8InPlace returns OperationStatus, therefore doesn't throw.
 91            // For Base64Url, this is not an OperationStatus API and thus throws.
 092            if (status == OperationStatus.InvalidData)
 93            {
 094                throw new FormatException(SR.Format_BadBase64Char);
 95            }
 96
 097            Debug.Assert(status is OperationStatus.Done);
 098            return bytesWritten;
 99        }
 100
 101        /// <summary>
 102        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 103        /// </summary>
 104        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 105        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 106        /// <returns>The number of bytes written into <paramref name="destination"/>. This can be used to slice the outp
 107        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the de
 108        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 109        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 110        /// <remarks>
 111        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 112        /// If the <paramref name="source"/> length is not a multiple of 4 the remainders decoded accordingly:
 113        /// - Remainder of 3 bytes - decoded into 2 bytes data, decoding succeeds.
 114        /// - Remainder of 2 bytes - decoded into 1 byte data. decoding succeeds.
 115        /// - Remainder of 1 byte - is invalid input, causes FormatException.
 116        /// </remarks>
 117        public static int DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination)
 118        {
 0119            OperationStatus status = DecodeFromUtf8(source, destination, out _, out int bytesWritten);
 120
 0121            if (status == OperationStatus.Done)
 122            {
 0123                return bytesWritten;
 124            }
 125
 0126            if (status == OperationStatus.DestinationTooSmall)
 127            {
 0128                throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 129            }
 130
 0131            Debug.Assert(status is OperationStatus.InvalidData);
 0132            throw new FormatException(SR.Format_BadBase64Char);
 133        }
 134
 135        /// <summary>
 136        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 137        /// </summary>
 138        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 139        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 140        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 141        /// <returns><see langword="true"/> if bytes decoded successfully, otherwise <see langword="false"/>.</returns>
 142        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 143        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 144        public static bool TryDecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
 145        {
 0146            OperationStatus status = DecodeFromUtf8(source, destination, out _, out bytesWritten);
 147
 0148            if (status == OperationStatus.InvalidData)
 149            {
 0150                throw new FormatException(SR.Format_BadBase64Char);
 151            }
 152
 0153            Debug.Assert(status is OperationStatus.Done or OperationStatus.DestinationTooSmall);
 0154            return status == OperationStatus.Done;
 155        }
 156
 157        /// <summary>
 158        /// Decodes the span of UTF-8 encoded text represented as Base64Url into binary data.
 159        /// </summary>
 160        /// <param name="source">The input span which contains UTF-8 encoded text in Base64Url that needs to be decoded.
 161        /// <returns>A byte array which contains the result of the decoding operation.</returns>
 162        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 163        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 164        public static unsafe byte[] DecodeFromUtf8(ReadOnlySpan<byte> source)
 165        {
 0166            int upperBound = GetMaxDecodedLength(source.Length);
 0167            byte[]? rented = null;
 168
 0169            Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
 0170                ? stackalloc byte[MaxStackallocThreshold]
 0171                : (rented = ArrayPool<byte>.Shared.Rent(upperBound));
 172
 0173            OperationStatus status = DecodeFromUtf8(source, destination, out _, out int bytesWritten);
 0174            Debug.Assert(status is OperationStatus.Done or OperationStatus.InvalidData);
 0175            byte[] ret = destination.Slice(0, bytesWritten).ToArray();
 176
 0177            if (rented is not null)
 178            {
 0179                ArrayPool<byte>.Shared.Return(rented);
 180            }
 181
 0182            return status == OperationStatus.Done ? ret : throw new FormatException(SR.Format_BadBase64Char);
 183        }
 184
 185        /// <summary>
 186        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 187        /// </summary>
 188        /// <param name="source">The input span which contains unicode ASCII chars in Base64Url that needs to be decoded
 189        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 190        /// <param name="charsConsumed">When this method returns, contains the number of input chars consumed during the
 191        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 192        /// <param name="isFinalBlock"><see langword="true"/> when the input span contains the entirety of data to decod
 193        /// such as when calling in a loop. Calls with <see langword="false"/> should be followed up with another call w
 194        /// <returns>One of the enumeration values that indicates the success or failure of the operation.</returns>
 195        /// <remarks>
 196        /// As padding is optional for Base64Url the <paramref name="source"/> length not required to be a multiple of 4
 197        /// If the <paramref name="source"/> length is not a multiple of 4 and <paramref name="isFinalBlock"/> is <see l
 198        /// - Remainder of 3 chars - decoded into 2 bytes data, decoding succeeds.
 199        /// - Remainder of 2 chars - decoded into 1 byte data. decoding succeeds.
 200        /// - Remainder of 1 char - will cause OperationStatus.InvalidData result.
 201        /// </remarks>
 202        public static OperationStatus DecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination,
 203            out int charsConsumed, out int bytesWritten, bool isFinalBlock = true) =>
 0204            DecodeFrom(default(Base64UrlDecoderChar), MemoryMarshal.Cast<char, ushort>(source), destination,
 0205                out charsConsumed, out bytesWritten, isFinalBlock, ignoreWhiteSpace: true);
 206
 207        /// <summary>
 208        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 209        /// </summary>
 210        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 211        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 212        /// <returns>The number of bytes written into the output span. This can be used to slice the output for subseque
 213        /// <exception cref="ArgumentException">The buffer in <paramref name="destination"/> is too small to hold the de
 214        /// <exception cref="FormatException"><paramref name="source"/> contains a invalid Base64Url character,
 215        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 216        public static int DecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination)
 217        {
 0218            OperationStatus status = DecodeFromChars(source, destination, out _, out int bytesWritten);
 219
 0220            if (status == OperationStatus.Done)
 221            {
 0222                return bytesWritten;
 223            }
 224
 0225            if (status == OperationStatus.DestinationTooSmall)
 226            {
 0227                throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
 228            }
 229
 0230            Debug.Assert(status == OperationStatus.InvalidData);
 0231            throw new FormatException(SR.Format_BadBase64Char);
 232        }
 233
 234        /// <summary>
 235        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 236        /// </summary>
 237        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 238        /// <param name="destination">The output span which contains the result of the operation, i.e. the decoded binar
 239        /// <param name="bytesWritten">When this method returns, contains the number of bytes written into the output sp
 240        /// <returns><see langword="true"/> if bytes decoded successfully, otherwise <see langword="false"/>.</returns>
 241        /// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64Url character,
 242        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 243        public static bool TryDecodeFromChars(ReadOnlySpan<char> source, Span<byte> destination, out int bytesWritten)
 244        {
 0245            OperationStatus status = DecodeFromChars(source, destination, out _, out bytesWritten);
 246
 0247            if (status == OperationStatus.InvalidData)
 248            {
 0249                throw new FormatException(SR.Format_BadBase64Char);
 250            }
 251
 0252            return status == OperationStatus.Done;
 253        }
 254
 255        /// <summary>
 256        /// Decodes the span of unicode ASCII chars represented as Base64Url into binary data.
 257        /// </summary>
 258        /// <param name="source">The input span which contains ASCII chars in Base64Url that needs to be decoded.</param
 259        /// <returns>A byte array which contains the result of the decoding operation.</returns>
 260        /// <exception cref="FormatException"><paramref name="source"/> contains a invalid Base64Url character,
 261        /// more than two padding characters, or a non white space character among the padding characters.</exception>
 262        public static unsafe byte[] DecodeFromChars(ReadOnlySpan<char> source)
 263        {
 0264            int upperBound = GetMaxDecodedLength(source.Length);
 0265            byte[]? rented = null;
 266
 0267            Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
 0268                ? stackalloc byte[MaxStackallocThreshold]
 0269                : (rented = ArrayPool<byte>.Shared.Rent(upperBound));
 270
 0271            OperationStatus status = DecodeFromChars(source, destination, out _, out int bytesWritten);
 0272            byte[] ret = destination.Slice(0, bytesWritten).ToArray();
 273
 0274            if (rented is not null)
 275            {
 0276                ArrayPool<byte>.Shared.Return(rented);
 277            }
 278
 0279            return status == OperationStatus.Done ? ret : throw new FormatException(SR.Format_BadBase64Char);
 280        }
 281
 282        private readonly struct Base64UrlDecoderByte : IBase64Decoder<byte>
 283        {
 284            public ReadOnlySpan<sbyte> DecodingMap =>
 0285                [
 0286                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0287                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0288                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1,         //62 is placed at index 45 (
 0289                    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,         //52-61 are placed at index 
 0290                    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
 0291                    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,         //0-25 are placed at index 6
 0292                    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
 0293                    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,         //26-51 are placed at index 
 0294                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,         // Bytes over 122 ('z') are 
 0295                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,         // Hence, padding the map wi
 0296                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0297                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0298                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0299                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0300                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0301                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0302                ];
 303
 304            public ReadOnlySpan<uint> VbmiLookup0 =>
 0305                [
 0306                    0x80808080, 0x80808080, 0x80808080, 0x80808080,
 0307                    0x80808080, 0x80808080, 0x80808080, 0x80808080,
 0308                    0x80808080, 0x80808080, 0x80808080, 0x80803e80,
 0309                    0x37363534, 0x3b3a3938, 0x80803d3c, 0x80808080
 0310                ];
 311
 312            public ReadOnlySpan<uint> VbmiLookup1 =>
 0313                [
 0314                    0x02010080, 0x06050403, 0x0a090807, 0x0e0d0c0b,
 0315                    0x1211100f, 0x16151413, 0x80191817, 0x3f808080,
 0316                    0x1c1b1a80, 0x201f1e1d, 0x24232221, 0x28272625,
 0317                    0x2c2b2a29, 0x302f2e2d, 0x80333231, 0x80808080
 0318                ];
 319
 320            public ReadOnlySpan<sbyte> Avx2LutHigh =>
 0321                [
 0322                    0x00, 0x00, 0x2d, 0x39,
 0323                    0x4f, 0x5a, 0x6f, 0x7a,
 0324                    0x00, 0x00, 0x00, 0x00,
 0325                    0x00, 0x00, 0x00, 0x00,
 0326                    0x00, 0x00, 0x2d, 0x39,
 0327                    0x4f, 0x5a, 0x6f, 0x7a,
 0328                    0x00, 0x00, 0x00, 0x00,
 0329                    0x00, 0x00, 0x00, 0x00
 0330                ];
 331
 332            public ReadOnlySpan<sbyte> Avx2LutLow =>
 0333                [
 0334                    0x01, 0x01, 0x2d, 0x30,
 0335                    0x41, 0x50, 0x61, 0x70,
 0336                    0x01, 0x01, 0x01, 0x01,
 0337                    0x01, 0x01, 0x01, 0x01,
 0338                    0x01, 0x01, 0x2d, 0x30,
 0339                    0x41, 0x50, 0x61, 0x70,
 0340                    0x01, 0x01, 0x01, 0x01,
 0341                    0x01, 0x01, 0x01, 0x01
 0342                ];
 343
 344            public ReadOnlySpan<sbyte> Avx2LutShift =>
 0345                [
 0346                    0,   0,  17,   4,
 0347                  -65, -65, -71, -71,
 0348                    0,   0,   0,   0,
 0349                    0,   0,   0,   0,
 0350                    0,   0,  17,   4,
 0351                  -65, -65, -71, -71,
 0352                    0,   0,   0,   0,
 0353                    0,   0,   0,   0
 0354                ];
 355
 0356            public byte MaskSlashOrUnderscore => (byte)'_'; // underscore
 357
 0358            public ReadOnlySpan<int> Vector128LutHigh => [0x392d0000, 0x7a6f5a4f, 0x00000000, 0x00000000];
 359
 0360            public ReadOnlySpan<int> Vector128LutLow => [0x302d0101, 0x70615041, 0x01010101, 0x01010101];
 361
 0362            public ReadOnlySpan<uint> Vector128LutShift => [0x04110000, 0xb9b9bfbf, 0x00000000, 0x00000000];
 363
 0364            public ReadOnlySpan<uint> AdvSimdLutOne3 => [0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3EFF];
 365
 0366            public uint AdvSimdLutTwo3Uint1 => 0x1B1AFF3F;
 367
 0368            public int GetMaxDecodedLength(int sourceLength) => Base64Url.GetMaxDecodedLength(sourceLength);
 369
 0370            public bool IsInvalidLength(int bufferLength) => (bufferLength & 3) == 1; // One byte cannot be decoded comp
 371
 0372            public bool IsValidPadding(uint padChar) => padChar is EncodingPad or UrlEncodingPad;
 373
 0374            public int SrcLength(bool isFinalBlock, int sourceLength) => isFinalBlock ? sourceLength : sourceLength & ~0
 375
 376#if NET
 377            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 378            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 379            [CompExactlyDependsOn(typeof(Ssse3))]
 380            [CompExactlyDependsOn(typeof(PackedSimd))]
 381            public bool TryDecode128Core(
 382                Vector128<byte> str,
 383                Vector128<byte> hiNibbles,
 384                Vector128<byte> maskSlashOrUnderscore,
 385                Vector128<byte> mask8F,
 386                Vector128<byte> lutLow,
 387                Vector128<byte> lutHigh,
 388                Vector128<sbyte> lutShift,
 389                Vector128<byte> shiftForUnderscore,
 390                out Vector128<byte> result)
 391            {
 0392                Vector128<byte> lowerBound = SimdShuffle(lutLow, hiNibbles, mask8F);
 0393                Vector128<byte> upperBound = SimdShuffle(lutHigh, hiNibbles, mask8F);
 394
 0395                Vector128<byte> below = Vector128.LessThan(str, lowerBound);
 0396                Vector128<byte> above = Vector128.GreaterThan(str, upperBound);
 0397                Vector128<byte> eq5F = Vector128.Equals(str, maskSlashOrUnderscore);
 398
 399                // Take care as arguments are flipped in order!
 0400                Vector128<byte> outside = Vector128.AndNot(below | above, eq5F);
 401
 0402                if (outside != Vector128<byte>.Zero)
 403                {
 0404                    result = default;
 0405                    return false;
 406                }
 407
 0408                Vector128<byte> shift = SimdShuffle(lutShift.AsByte(), hiNibbles, mask8F);
 0409                str += shift;
 410
 0411                result = str + (eq5F & shiftForUnderscore);
 0412                return true;
 413            }
 414
 415            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 416            [CompExactlyDependsOn(typeof(Avx2))]
 417            public bool TryDecode256Core(
 418                Vector256<sbyte> str,
 419                Vector256<sbyte> hiNibbles,
 420                Vector256<sbyte> maskSlashOrUnderscore,
 421                Vector256<sbyte> lutLow,
 422                Vector256<sbyte> lutHigh,
 423                Vector256<sbyte> lutShift,
 424                Vector256<sbyte> shiftForUnderscore,
 425                out Vector256<sbyte> result)
 426            {
 0427                Vector256<sbyte> lowerBound = Avx2.Shuffle(lutLow, hiNibbles);
 0428                Vector256<sbyte> upperBound = Avx2.Shuffle(lutHigh, hiNibbles);
 429
 0430                Vector256<sbyte> below = Vector256.LessThan(str, lowerBound);
 0431                Vector256<sbyte> above = Vector256.GreaterThan(str, upperBound);
 0432                Vector256<sbyte> eq5F = Vector256.Equals(str, maskSlashOrUnderscore);
 433
 434                // Take care as arguments are flipped in order!
 0435                Vector256<sbyte> outside = Vector256.AndNot(below | above, eq5F);
 436
 0437                if (outside != Vector256<sbyte>.Zero)
 438                {
 0439                    result = default;
 0440                    return false;
 441                }
 442
 0443                Vector256<sbyte> shift = Avx2.Shuffle(lutShift, hiNibbles);
 0444                str += shift;
 445
 0446                result = str + (eq5F & shiftForUnderscore);
 0447                return true;
 448            }
 449
 450            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 451            public unsafe bool TryLoadVector512(byte* src, byte* srcStart, int sourceLength, out Vector512<sbyte> str) =
 0452                default(Base64DecoderByte).TryLoadVector512(src, srcStart, sourceLength, out str);
 453
 454            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 455            [CompExactlyDependsOn(typeof(Avx2))]
 456            public unsafe bool TryLoadAvxVector256(byte* src, byte* srcStart, int sourceLength, out Vector256<sbyte> str
 0457                default(Base64DecoderByte).TryLoadAvxVector256(src, srcStart, sourceLength, out str);
 458
 459            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 460            public unsafe bool TryLoadVector128(byte* src, byte* srcStart, int sourceLength, out Vector128<byte> str) =>
 0461                default(Base64DecoderByte).TryLoadVector128(src, srcStart, sourceLength, out str);
 462
 463            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 464            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 465            public unsafe bool TryLoadArmVector128x4(byte* src, byte* srcStart, int sourceLength,
 466                out Vector128<byte> str1, out Vector128<byte> str2, out Vector128<byte> str3, out Vector128<byte> str4) 
 0467                default(Base64DecoderByte).TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out st
 468#endif // NET
 469
 470            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 471            public unsafe int DecodeFourElements(byte* source, ref sbyte decodingMap) =>
 0472                default(Base64DecoderByte).DecodeFourElements(source, ref decodingMap);
 473
 474            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 475            public unsafe int DecodeRemaining(byte* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out uint
 0476                default(Base64DecoderByte).DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3);
 477
 478            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 0479            public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan<byte> span) => default(Base64DecoderByte).IndexOfAnyExcep
 480
 481            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 482            [SuppressReadyToRunCanonicalRooting]
 483            public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper<TBase64Decoder>(TBase64Decoder decoder, ReadOnly
 484                ref int bytesConsumed, ref int bytesWritten, bool isFinalBlock = true) where TBase64Decoder : IBase64Dec
 0485                DecodeWithWhiteSpaceBlockwise(decoder, utf8, bytes, ref bytesConsumed, ref bytesWritten, isFinalBlock);
 486        }
 487
 488        private readonly struct Base64UrlDecoderChar : IBase64Decoder<ushort>
 489        {
 0490            public ReadOnlySpan<sbyte> DecodingMap => default(Base64UrlDecoderByte).DecodingMap;
 491
 0492            public ReadOnlySpan<uint> VbmiLookup0 => default(Base64UrlDecoderByte).VbmiLookup0;
 493
 0494            public ReadOnlySpan<uint> VbmiLookup1 => default(Base64UrlDecoderByte).VbmiLookup1;
 495
 0496            public ReadOnlySpan<sbyte> Avx2LutHigh => default(Base64UrlDecoderByte).Avx2LutHigh;
 497
 0498            public ReadOnlySpan<sbyte> Avx2LutLow => default(Base64UrlDecoderByte).Avx2LutLow;
 499
 0500            public ReadOnlySpan<sbyte> Avx2LutShift => default(Base64UrlDecoderByte).Avx2LutShift;
 501
 0502            public byte MaskSlashOrUnderscore => default(Base64UrlDecoderByte).MaskSlashOrUnderscore;
 503
 0504            public ReadOnlySpan<int> Vector128LutHigh => default(Base64UrlDecoderByte).Vector128LutHigh;
 505
 0506            public ReadOnlySpan<int> Vector128LutLow => default(Base64UrlDecoderByte).Vector128LutLow;
 507
 0508            public ReadOnlySpan<uint> Vector128LutShift => default(Base64UrlDecoderByte).Vector128LutShift;
 509
 0510            public ReadOnlySpan<uint> AdvSimdLutOne3 => default(Base64UrlDecoderByte).AdvSimdLutOne3;
 511
 0512            public uint AdvSimdLutTwo3Uint1 => default(Base64UrlDecoderByte).AdvSimdLutTwo3Uint1;
 513
 0514            public int GetMaxDecodedLength(int sourceLength) => default(Base64UrlDecoderByte).GetMaxDecodedLength(source
 515
 0516            public bool IsInvalidLength(int bufferLength) => default(Base64UrlDecoderByte).IsInvalidLength(bufferLength)
 517
 0518            public bool IsValidPadding(uint padChar) => default(Base64UrlDecoderByte).IsValidPadding(padChar);
 519
 0520            public int SrcLength(bool isFinalBlock, int sourceLength) => default(Base64UrlDecoderByte).SrcLength(isFinal
 521
 522#if NET
 523            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 524            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 525            [CompExactlyDependsOn(typeof(Ssse3))]
 526            [CompExactlyDependsOn(typeof(PackedSimd))]
 527            public bool TryDecode128Core(Vector128<byte> str, Vector128<byte> hiNibbles, Vector128<byte> maskSlashOrUnde
 528                Vector128<byte> lutLow, Vector128<byte> lutHigh, Vector128<sbyte> lutShift, Vector128<byte> shiftForUnde
 0529                default(Base64UrlDecoderByte).TryDecode128Core(str, hiNibbles, maskSlashOrUnderscore, mask8F, lutLow, lu
 530
 531            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 532            [CompExactlyDependsOn(typeof(Avx2))]
 533            public bool TryDecode256Core(Vector256<sbyte> str, Vector256<sbyte> hiNibbles, Vector256<sbyte> maskSlashOrU
 534                Vector256<sbyte> lutHigh, Vector256<sbyte> lutShift, Vector256<sbyte> shiftForUnderscore, out Vector256<
 0535                default(Base64UrlDecoderByte).TryDecode256Core(str, hiNibbles, maskSlashOrUnderscore, lutLow, lutHigh, l
 536
 537            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 538            public unsafe bool TryLoadVector512(ushort* src, ushort* srcStart, int sourceLength, out Vector512<sbyte> st
 0539                default(Base64DecoderChar).TryLoadVector512(src, srcStart, sourceLength, out str);
 540
 541            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 542            [CompExactlyDependsOn(typeof(Avx2))]
 543            public unsafe bool TryLoadAvxVector256(ushort* src, ushort* srcStart, int sourceLength, out Vector256<sbyte>
 0544                default(Base64DecoderChar).TryLoadAvxVector256(src, srcStart, sourceLength, out str);
 545
 546            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 547            public unsafe bool TryLoadVector128(ushort* src, ushort* srcStart, int sourceLength, out Vector128<byte> str
 0548                default(Base64DecoderChar).TryLoadVector128(src, srcStart, sourceLength, out str);
 549
 550            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 551            [CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
 552            public unsafe bool TryLoadArmVector128x4(ushort* src, ushort* srcStart, int sourceLength,
 553                out Vector128<byte> str1, out Vector128<byte> str2, out Vector128<byte> str3, out Vector128<byte> str4) 
 0554                default(Base64DecoderChar).TryLoadArmVector128x4(src, srcStart, sourceLength, out str1, out str2, out st
 555#endif // NET
 556
 557            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 558            public unsafe int DecodeFourElements(ushort* source, ref sbyte decodingMap) =>
 0559                default(Base64DecoderChar).DecodeFourElements(source, ref decodingMap);
 560
 561            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 562            public unsafe int DecodeRemaining(ushort* srcEnd, ref sbyte decodingMap, long remaining, out uint t2, out ui
 0563                default(Base64DecoderChar).DecodeRemaining(srcEnd, ref decodingMap, remaining, out t2, out t3);
 564
 565            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 0566            public int IndexOfAnyExceptWhiteSpace(ReadOnlySpan<ushort> span) => default(Base64DecoderChar).IndexOfAnyExc
 567
 568            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 569            [SuppressReadyToRunCanonicalRooting]
 570            public OperationStatus DecodeWithWhiteSpaceBlockwiseWrapper<TBase64Decoder>(TBase64Decoder decoder, ReadOnly
 571                ref int bytesConsumed, ref int bytesWritten, bool isFinalBlock = true) where TBase64Decoder : IBase64Dec
 0572                DecodeWithWhiteSpaceBlockwise(decoder, source, bytes, ref bytesConsumed, ref bytesWritten, isFinalBlock)
 573        }
 574    }
 575}

D:\runner\runtime\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
 052            ArgumentOutOfRangeException.ThrowIfGreaterThan<uint>((uint)bytesLength, MaximumEncodeLength);
 53
 054            (uint whole, uint remainder) = uint.DivRem((uint)bytesLength, 3);
 55
 056            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) =>
 0118            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
 0165            int encodedLength = GetEncodedLength(source.Length);
 166
 0167            return string.Create(encodedLength, (IntPtr)(&source), static (buffer, spanPtr) =>
 0168            {
 0169                ReadOnlySpan<byte> source = *(ReadOnlySpan<byte>*)spanPtr;
 0170                EncodeToChars(source, buffer, out _, out int charsWritten);
 0171                Debug.Assert(buffer.Length == charsWritten, $"The source length: {source.Length}, bytes written: {charsW
 0172            });
 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        {
 0225            OperationStatus status = EncodeToUtf8InPlace(default(Base64UrlEncoderByte), buffer, dataLength, out bytesWri
 226
 0227            return status == OperationStatus.Done;
 228        }
 229
 230        private readonly struct Base64UrlEncoderByte : Base64Helper.IBase64Encoder<byte>
 231        {
 0232            public ReadOnlySpan<byte> EncodingMap => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"u
 233
 0234            public sbyte Avx2LutChar62 => -17;  // char '-' diff
 235
 0236            public sbyte Avx2LutChar63 => 32;   // char '_' diff
 237
 0238            public ReadOnlySpan<byte> AdvSimdLut4 => "wxyz0123456789-_"u8;
 239
 0240            public uint Ssse3AdvSimdLutE3 => 0x000020EF;
 241
 0242            public int IncrementPadTwo => 2;
 243
 0244            public int IncrementPadOne => 3;
 245
 246            public int GetMaxSrcLength(int srcLength, int destLength) =>
 0247                srcLength <= MaximumEncodeLength && destLength >= GetEncodedLength(srcLength) ?
 0248                srcLength : GetMaxDecodedLength(destLength);
 249
 250            public uint GetInPlaceDestinationLength(int encodedLength, int leftOver) =>
 0251                leftOver > 0 ? (uint)(encodedLength - leftOver - 1) : (uint)(encodedLength - 4);
 252
 0253            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
 0260                uint i = t0 << 8;
 261
 0262                byte i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 10));
 0263                byte i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 4) & 0x3F));
 264
 265                ushort result;
 266
 0267                if (BitConverter.IsLittleEndian)
 268                {
 0269                    result = (ushort)(i0 | (i1 << 8));
 270                }
 271                else
 272                {
 273                    result = (ushort)((i0 << 8) | i1);
 274                }
 275
 0276                Unsafe.WriteUnaligned(dest, result);
 0277            }
 278
 279            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 280            public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, byte* dest, ref byte encodingMap)
 281            {
 0282                uint t0 = twoBytes[0];
 0283                uint t1 = twoBytes[1];
 284
 0285                uint i = (t0 << 16) | (t1 << 8);
 286
 0287                byte i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 18));
 0288                byte i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 12) & 0x3F));
 0289                byte i2 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 6) & 0x3F));
 290
 0291                dest[0] = i0;
 0292                dest[1] = i1;
 0293                dest[2] = i2;
 0294            }
 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        {
 0324            public ReadOnlySpan<byte> EncodingMap => default(Base64UrlEncoderByte).EncodingMap;
 325
 0326            public sbyte Avx2LutChar62 => default(Base64UrlEncoderByte).Avx2LutChar62;
 327
 0328            public sbyte Avx2LutChar63 => default(Base64UrlEncoderByte).Avx2LutChar63;
 329
 0330            public ReadOnlySpan<byte> AdvSimdLut4 => default(Base64UrlEncoderByte).AdvSimdLut4;
 331
 0332            public uint Ssse3AdvSimdLutE3 => default(Base64UrlEncoderByte).Ssse3AdvSimdLutE3;
 333
 0334            public int IncrementPadTwo => default(Base64UrlEncoderByte).IncrementPadTwo;
 335
 0336            public int IncrementPadOne => default(Base64UrlEncoderByte).IncrementPadOne;
 337
 338            public int GetMaxSrcLength(int srcLength, int destLength) =>
 0339                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) =>
 0347                Base64Helper.EncodeOneOptionallyPadTwo(oneByte, dest, ref encodingMap);
 348
 349            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 350            public unsafe void EncodeTwoOptionallyPadOne(byte* twoBytes, ushort* dest, ref byte encodingMap) =>
 0351                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
 0356                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
 0360                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
 0364                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) =>
 0375                default(Base64EncoderChar).EncodeThreeAndWrite(threeBytes, destination, ref encodingMap);
 376        }
 377    }
 378}

D:\runner\runtime\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) =>
 053            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
 086            private static readonly SearchValues<byte> s_validBase64UrlChars = SearchValues.Create(default(Base64UrlEnco
 87
 088            public int IndexOfAnyExcept(ReadOnlySpan<byte> span) => span.IndexOfAnyExcept(s_validBase64UrlChars);
 89#else
 90            public int DecodeValue(byte value) => default(Base64UrlDecoderByte).DecodingMap[value];
 91#endif
 092            public bool IsWhiteSpace(byte value) => Base64Helper.IsWhiteSpace(value);
 093            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.
 098                int remainder = (int)((uint)length % 4);
 99
 0100                if (paddingCount != 0)
 101                {
 0102                    length -= paddingCount;
 0103                    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 
 0106                    if (remainder == 0 || remainder + paddingCount > 4)
 107                    {
 0108                        decodedLength = 0;
 0109                        return false;
 110                    }
 111                }
 112
 0113                decodedLength = (length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0);
 114
 0115                if (remainder > 0)
 116                {
 0117                    int decoded = default(Base64UrlDecoderByte).DecodingMap[lastChar];
 118                    switch (remainder)
 119                    {
 0120                        case 1: return false; // 1 byte is not decodable => invalid.
 0121                        case 2: return ((decoded & 0x0F) == 0); // if unused lower 4 bits are set to 0
 0122                        case 3: return ((decoded & 0x03) == 0); // if unused lower 2 bits are set to 0
 123                    }
 124                }
 125
 0126                return true;
 127            }
 128        }
 129    }
 130}

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&)