-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry pick branch 'genexuslabs:gamutils_eo' into beta
- Loading branch information
Showing
10 changed files
with
366 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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
74 changes: 74 additions & 0 deletions
74
dotnet/src/extensions/gam/src/DotNetFramework/GamUtils/Utils/Json/JWTAlgorithm.cs
This file contains 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,74 @@ | ||
using Jose; | ||
using log4net; | ||
|
||
namespace GamUtils.Utils.Json | ||
{ | ||
public enum JWTAlgorithm | ||
{ | ||
none, HS256, HS384, HS512, RS256, RS512 | ||
} | ||
|
||
public class JWTAlgorithmUtils | ||
{ | ||
private static readonly ILog logger = LogManager.GetLogger(typeof(JWTAlgorithmUtils)); | ||
internal static JwsAlgorithm GetJWSAlgorithm(JWTAlgorithm alg) | ||
{ | ||
logger.Debug("GetJWSAlgorithm"); | ||
switch (alg) | ||
{ | ||
case JWTAlgorithm.HS256: | ||
return JwsAlgorithm.HS256; | ||
case JWTAlgorithm.HS512: | ||
return JwsAlgorithm.HS512; | ||
case JWTAlgorithm.HS384: | ||
return JwsAlgorithm.HS384; | ||
case JWTAlgorithm.RS256: | ||
return JwsAlgorithm.RS256; | ||
case JWTAlgorithm.RS512: | ||
return JwsAlgorithm.RS512; | ||
default: | ||
logger.Error("GetJWSAlgorithm - not implemented algorithm"); | ||
return JwsAlgorithm.none; | ||
} | ||
} | ||
|
||
internal static JWTAlgorithm GetJWTAlgoritm(string alg) | ||
{ | ||
logger.Debug("GetJWTAlgoritm"); | ||
switch (alg.Trim().ToUpper()) | ||
{ | ||
case "HS256": | ||
return JWTAlgorithm.HS256; | ||
case "HS512": | ||
return JWTAlgorithm.HS512; | ||
case "HS384": | ||
return JWTAlgorithm.HS384; | ||
case "RS256": | ||
return JWTAlgorithm.RS256; | ||
case "RS512": | ||
return JWTAlgorithm.RS512; | ||
default: | ||
logger.Error("GetJWTAlgoritm- not implemented algorithm"); | ||
return JWTAlgorithm.none; | ||
} | ||
} | ||
|
||
internal static bool IsSymmetric(JWTAlgorithm alg) | ||
{ | ||
logger.Debug("IsSymmetric"); | ||
switch (alg) | ||
{ | ||
case JWTAlgorithm.HS256: | ||
case JWTAlgorithm.HS384: | ||
case JWTAlgorithm.HS512: | ||
return true; | ||
case JWTAlgorithm.RS256: | ||
case JWTAlgorithm.RS512: | ||
return false; | ||
default: | ||
logger.Error("IsSymmetric - not implemented algorithm"); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.