-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[dotnet] Remove Microsoft.IdentityModel.Tokens as dependency #12777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
titusfortner
merged 9 commits into
SeleniumHQ:trunk
from
nvborisenko:dotnet-dep-identitymodel
Sep 25, 2023
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1adb8b1
Remove Microsoft.IdentityModel.Tokens as dependency
nvborisenko 00182e2
Make it internal
nvborisenko bf31568
Remove unused methods
nvborisenko c474300
One more unused method
nvborisenko dc4e060
Remove unused using namespace
nvborisenko 7db931d
Add standard copyright file notice
nvborisenko 5163d61
Combine 2 methods
nvborisenko 9c66bc8
Add links to original source as comments
nvborisenko fa569db
Merge branch 'trunk' into dotnet-dep-identitymodel
nvborisenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// Thanks to Microsoft.IdentityModel.Tokens package for this code. | ||
// https://raw.githubusercontent.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/6.19.0/src/Microsoft.IdentityModel.Tokens/Base64UrlEncoder.cs | ||
using System; | ||
|
||
namespace OpenQA.Selenium.Internal | ||
{ | ||
/// <summary> | ||
/// Encodes and Decodes strings as Base64Url encoding. | ||
/// </summary> | ||
internal static class Base64UrlEncoder | ||
{ | ||
private const char base64PadCharacter = '='; | ||
private const string doubleBase64PadCharacter = "=="; | ||
private const char base64Character62 = '+'; | ||
private const char base64Character63 = '/'; | ||
private const char base64UrlCharacter62 = '-'; | ||
private const char base64UrlCharacter63 = '_'; | ||
|
||
/// <summary> | ||
/// Encoding table | ||
/// </summary> | ||
internal static readonly char[] s_base64Table = | ||
{ | ||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', | ||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', | ||
'0','1','2','3','4','5','6','7','8','9', | ||
base64UrlCharacter62, | ||
base64UrlCharacter63 | ||
}; | ||
|
||
/// <summary> | ||
/// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation which is encoded with base-64-url digits. Parameters specify | ||
/// the subset as an offset in the input array, and the number of elements in the array to convert. | ||
/// </summary> | ||
/// <param name="inArray">An array of 8-bit unsigned integers.</param> | ||
/// <param name="length">An offset in inArray.</param> | ||
/// <param name="offset">The number of elements of inArray to convert.</param> | ||
/// <returns>The string representation in base 64 url encoding of length elements of inArray, starting at position offset.</returns> | ||
/// <exception cref="ArgumentNullException">'inArray' is null.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">offset or length is negative OR offset plus length is greater than the length of inArray.</exception> | ||
public static string Encode(byte[] inArray, int offset, int length) | ||
titusfortner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
_ = inArray ?? throw new ArgumentNullException(nameof(inArray)); | ||
|
||
if (length == 0) | ||
return string.Empty; | ||
|
||
if (length < 0) | ||
throw new ArgumentOutOfRangeException(nameof(length)); | ||
|
||
if (offset < 0 || inArray.Length < offset) | ||
throw new ArgumentOutOfRangeException(nameof(offset)); | ||
|
||
if (inArray.Length < offset + length) | ||
throw new ArgumentOutOfRangeException(nameof(length)); | ||
|
||
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); | ||
} | ||
|
||
/// <summary> | ||
/// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation which is encoded with base-64-url digits. | ||
/// </summary> | ||
/// <param name="inArray">An array of 8-bit unsigned integers.</param> | ||
/// <returns>The string representation in base 64 url encoding of length elements of inArray, starting at position offset.</returns> | ||
/// <exception cref="ArgumentNullException">'inArray' is null.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">offset or length is negative OR offset plus length is greater than the length of inArray.</exception> | ||
public static string Encode(byte[] inArray) | ||
titusfortner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
_ = inArray ?? throw new ArgumentNullException(nameof(inArray)); | ||
|
||
return Encode(inArray, 0, inArray.Length); | ||
} | ||
|
||
/// <summary> | ||
/// Converts the specified string, which encodes binary data as base-64-url digits, to an equivalent 8-bit unsigned integer array.</summary> | ||
/// <param name="str">base64Url encoded string.</param> | ||
/// <returns>UTF8 bytes.</returns> | ||
public static byte[] DecodeBytes(string str) | ||
titusfortner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
_ = str ?? throw new ArgumentNullException(nameof(str)); | ||
|
||
// 62nd char of encoding | ||
str = str.Replace(base64UrlCharacter62, base64Character62); | ||
|
||
// 63rd char of encoding | ||
str = str.Replace(base64UrlCharacter63, base64Character63); | ||
|
||
// check for padding | ||
switch (str.Length % 4) | ||
{ | ||
case 0: | ||
// No pad chars in this case | ||
break; | ||
case 2: | ||
// Two pad chars | ||
str += doubleBase64PadCharacter; | ||
break; | ||
case 3: | ||
// One pad char | ||
str += base64PadCharacter; | ||
break; | ||
default: | ||
throw new FormatException(str); | ||
} | ||
|
||
return Convert.FromBase64String(str); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-64.7 KB
third_party/dotnet/nuget/packages/microsoft.identitymodel.abstractions.6.19.0.nupkg
Binary file not shown.
Binary file removed
BIN
-95 KB
third_party/dotnet/nuget/packages/microsoft.identitymodel.logging.6.19.0.nupkg
Binary file not shown.
Binary file removed
BIN
-1.58 MB
third_party/dotnet/nuget/packages/microsoft.identitymodel.tokens.6.19.0.nupkg
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.