Skip to content

Commit ae8796e

Browse files
sgramponeBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:feat/gamutils_isHexa' into beta
1 parent bfa09d9 commit ae8796e

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

dotnet/src/extensions/gam/src/DotNetFramework/GamUtils/GamUtilsEO.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public static string RandomUrlSafeCharacters(int length)
102102
[SecuritySafeCritical]
103103
public static string Base64ToHexa(string base64) { return Encoding.Base64ToHexa(base64); }
104104

105+
[SecuritySafeCritical]
106+
public static bool IsHexadecimal(string base64) { return Encoding.IsHexa(base64); }
107+
105108
//**PKCE**//
106109

107110
[SecuritySafeCritical]

dotnet/src/extensions/gam/src/DotNetFramework/GamUtils/Utils/Encoding.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ internal static string Base64ToHexa(string base64)
8585
}
8686
}
8787

88+
[SecuritySafeCritical]
89+
internal static bool IsHexa(string hexa)
90+
{
91+
logger.Debug("IsHexa");
92+
try
93+
{
94+
Hex.Decode(hexa);
95+
}
96+
catch (Exception e)
97+
{
98+
logger.Error("IsHexa", e);
99+
return false;
100+
}
101+
return true;
102+
}
103+
88104

89105
}
90106
}

dotnet/src/extensions/gam/test/DotNetFramework/GamTest/Utils/TestEncoding.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,22 @@ private static string B64ToHexa(string base64)
9393
}
9494
}
9595

96+
[Test]
97+
public void IsHexa()
98+
{
99+
int i = 0;
100+
do
101+
{
102+
string randomHexa = GamUtilsEO.RandomHexaBits(128);
103+
bool hexa = GamUtilsEO.IsHexadecimal(randomHexa);
104+
Assert.IsTrue(hexa, "IsHexa_true");
105+
106+
string randomAlphanumeric = GamUtilsEO.RandomAlphanumeric(128);
107+
bool notHexa = GamUtilsEO.IsHexadecimal(randomAlphanumeric);
108+
Assert.IsFalse(notHexa, "testIsHexa_false");
109+
i++;
110+
} while (i < 50);
111+
}
112+
96113
}
97114
}

0 commit comments

Comments
 (0)