in src/Microsoft.Azure.SignalR.Common/Auth/Base64UrlEncoder.cs [70:139]
public static string Encode(byte[] inArray, int offset, int length)
{
_ = inArray ?? throw LogHelper.LogArgumentNullException(nameof(inArray));
if (length == 0)
return string.Empty;
// Modifications 1 starts from here
if (length < 0)
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException(LogHelper.FormatInvariant("IDX10106: The parameter {0} had an invalid value: '{1}'.", nameof(length), length)));
if (offset < 0 || inArray.Length < offset)
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException(LogHelper.FormatInvariant("IDX10106: The parameter {0} had an invalid value: '{1}'.", nameof(offset), offset)));
if (inArray.Length < offset + length)
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException(LogHelper.FormatInvariant("IDX10106: The parameter {0} had an invalid value: '{1}'.", nameof(length), length)));
// Modifications 1 ends here
int lengthmod3 = length % 3;
int limit = offset + (length - lengthmod3);
char[] output = new char[(length + 2) / 3 * 4];
char[] table = s_base64Table;
int i, j = 0;
// takes 3 bytes from inArray and insert 4 bytes into output
for (i = offset; i < limit; i += 3)
{
byte d0 = inArray[i];
byte d1 = inArray[i + 1];
byte d2 = inArray[i + 2];
output[j + 0] = table[d0 >> 2];
output[j + 1] = table[((d0 & 0x03) << 4) | (d1 >> 4)];
output[j + 2] = table[((d1 & 0x0f) << 2) | (d2 >> 6)];
output[j + 3] = table[d2 & 0x3f];
j += 4;
}
//Where we left off before
i = limit;
switch (lengthmod3)
{
case 2:
{
byte d0 = inArray[i];
byte d1 = inArray[i + 1];
output[j + 0] = table[d0 >> 2];
output[j + 1] = table[((d0 & 0x03) << 4) | (d1 >> 4)];
output[j + 2] = table[(d1 & 0x0f) << 2];
j += 3;
}
break;
case 1:
{
byte d0 = inArray[i];
output[j + 0] = table[d0 >> 2];
output[j + 1] = table[(d0 & 0x03) << 4];
j += 2;
}
break;
//default or case 0: no further operations are needed.
}
return new string(output, 0, j);
}