Skip to content

Commit 7236f9c

Browse files
sgramponeBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:gamutils_eo' into beta
1 parent e48d411 commit 7236f9c

File tree

4 files changed

+6
-53
lines changed

4 files changed

+6
-53
lines changed

gamutils/src/main/java/com/genexus/gam/GamUtilsEO.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public static String randomHexaBits(int bits) {
4242
return Random.hexaBits(bits);
4343
}
4444

45-
public static String randomUtf8Bits(int bits) {
46-
return Random.utf8Bits(bits);
47-
}
48-
4945
//**JWK**//
5046

5147
public static String generateKeyPair() {

gamutils/src/main/java/com/genexus/gam/utils/Random.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,4 @@ public static String hexaBits(int bits)
6060
}
6161
return sb.toString().replaceAll("\\s", "");
6262
}
63-
64-
public static String utf8Bits(int bits)
65-
{
66-
int targetBytes = (bits + 7) / 8;
67-
StringBuilder sb = new StringBuilder();
68-
for (int i = 0; i < targetBytes; i++) {
69-
sb.append("a");
70-
}
71-
String result = sb.toString();
72-
byte[] utf8Bytes = sb.toString().getBytes(StandardCharsets.UTF_8);
73-
if (utf8Bytes.length > targetBytes) {
74-
return new String(utf8Bytes, 0, targetBytes, StandardCharsets.UTF_8);
75-
} else if (utf8Bytes.length < targetBytes) {
76-
StringBuilder paddedString = new StringBuilder(sb.toString());
77-
for (int i = utf8Bytes.length; i < targetBytes; i++) {
78-
paddedString.append("0");
79-
}
80-
return paddedString.toString();
81-
}
82-
return result;
83-
}
8463
}

gamutils/src/test/java/com/genexus/gam/utils/test/JwtTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ public void test_json_Sha256()
149149
" \"alg\": \"HS256\",\n" +
150150
" \"typ\": \"JWT\"\n" +
151151
"}";
152-
int[] lengths = new int[]{256, 512, 1024};
152+
int[] lengths = new int[]{32, 64, 128};
153153
for (int n : lengths) {
154-
String secret = GamUtilsEO.randomUtf8Bits(n);
154+
String secret = GamUtilsEO.randomAlphanumeric(n);
155155
String token = GamUtilsEO.createJwtSha(secret, payload, header);
156156
Assert.assertFalse("test_json_Sha256 create", token.isEmpty());
157157
boolean result = GamUtilsEO.verifyJwtSha(secret, token);
@@ -166,9 +166,9 @@ public void test_json_Sha512()
166166
" \"alg\": \"HS512\",\n" +
167167
" \"typ\": \"JWT\"\n" +
168168
"}";
169-
int[] lengths = new int[]{512, 1024};
169+
int[] lengths = new int[]{64, 128};
170170
for (int n : lengths) {
171-
String secret = GamUtilsEO.randomUtf8Bits(n);
171+
String secret = GamUtilsEO.randomAlphanumeric(n);
172172
String token = GamUtilsEO.createJwtSha(secret, payload, header);
173173
Assert.assertFalse("test_json_Sha512 create", token.isEmpty());
174174
boolean result = GamUtilsEO.verifyJwtSha(secret, token);
@@ -183,7 +183,7 @@ public void test_VerifyAlgorithm_True()
183183
" \"alg\": \"HS512\",\n" +
184184
" \"typ\": \"JWT\"\n" +
185185
"}";
186-
String secret = GamUtilsEO.randomUtf8Bits(512);
186+
String secret = GamUtilsEO.randomAlphanumeric(64);
187187
String token = GamUtilsEO.createJwtSha(secret, payload, header);
188188
boolean resultSha512 = GamUtilsEO.verifyAlgorithm("HS512", token);
189189
Assert.assertTrue("test_VerifyAlgorithm_True", resultSha512);
@@ -196,7 +196,7 @@ public void test_VerifyAlgorithm_False()
196196
" \"alg\": \"HS512\",\n" +
197197
" \"typ\": \"JWT\"\n" +
198198
"}";
199-
String secret = GamUtilsEO.randomUtf8Bits(512);
199+
String secret = GamUtilsEO.randomAlphanumeric(64);
200200
String token = GamUtilsEO.createJwtSha(secret, payload, header);
201201
boolean resultSha512 = GamUtilsEO.verifyAlgorithm("RS256", token);
202202
Assert.assertFalse("test_VerifyAlgorithm_False", resultSha512);

gamutils/src/test/java/com/genexus/gam/utils/test/RandomTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,4 @@ public void testHexaBits() {
7575
}
7676
}
7777
}
78-
79-
@Test
80-
public void TestUtf8Bits()
81-
{
82-
int[] lengths = new int[]{32, 64, 128, 256, 512, 1024};
83-
84-
for (int n : lengths) {
85-
String utf8 = GamUtilsEO.randomUtf8Bits(n);
86-
Assert.assertFalse("TestUtf8Bits", utf8.isEmpty());
87-
try
88-
{
89-
byte[] decoded = utf8.getBytes(StandardCharsets.UTF_8);//Hex.decode(hexa);
90-
if(decoded.length != (n + 7) / 8)
91-
{
92-
Assert.fail("TestUtf8Bits wrong utf8 length");
93-
}
94-
}catch(Exception e)
95-
{
96-
Assert.fail("TestUtf8Bits not utf8 characters" + e.getMessage());
97-
}
98-
}
99-
}
10078
}

0 commit comments

Comments
 (0)