File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
main/java/com/inrupt/client/openid
test/java/com/inrupt/client/openid Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 3636 */
3737public final class PKCE {
3838
39+ private static final BigInteger PADDING = BigInteger .ofValue (2 ).pow (256 );
40+
3941 /**
4042 * Create a PKCE challenge value using the S256 algorithm.
4143 *
@@ -73,7 +75,7 @@ static String createChallenge(final String verifier, final String alg) {
7375 * @return the Base64URL-encoded verifier
7476 */
7577 static String createVerifier () {
76- final byte [] rand = new BigInteger (32 * 8 , new SecureRandom ()).toByteArray ();
78+ final byte [] rand = PADDING . add ( new BigInteger (32 * 8 , new SecureRandom () )).toByteArray ();
7779 return Base64 .getUrlEncoder ().withoutPadding ().encodeToString (rand );
7880 }
7981
Original file line number Diff line number Diff line change @@ -30,16 +30,16 @@ class PKCETest {
3030
3131 @ Test
3232 void createChallengeTest () {
33- assertTrue (PKCE .createChallenge ("🐶🐶🐶" , "SHA-256" ).getBytes ( UTF_8 ). length >= 43 );
34- assertTrue (PKCE .createChallenge ("🐶🐶🐶" , "SHA-256" ).getBytes ( UTF_8 ). length <= 128 );
35- assertTrue (PKCE .createChallenge ("" , "SHA-256" ).getBytes ( UTF_8 ). length >= 43 );
36- assertTrue (PKCE .createChallenge ("" , "SHA-256" ).getBytes ( UTF_8 ). length <= 128 );
33+ assertTrue (PKCE .createChallenge ("🐶🐶🐶" , "SHA-256" ).length () >= 43 );
34+ assertTrue (PKCE .createChallenge ("🐶🐶🐶" , "SHA-256" ).length () <= 128 );
35+ assertTrue (PKCE .createChallenge ("" , "SHA-256" ).length () >= 43 );
36+ assertTrue (PKCE .createChallenge ("" , "SHA-256" ).length () <= 128 );
3737 assertThrows (NullPointerException .class , () -> PKCE .createChallenge (null , "SHA-256" ));
3838 }
3939
4040 @ Test
4141 void createVerifierTest () {
42- assertTrue (PKCE .createVerifier ().getBytes ( UTF_8 ). length >= 43 );
43- assertTrue (PKCE .createVerifier ().getBytes ( UTF_8 ). length <= 128 );
42+ assertTrue (PKCE .createVerifier ().length () >= 43 );
43+ assertTrue (PKCE .createVerifier ().length () <= 128 );
4444 }
4545}
You can’t perform that action at this time.
0 commit comments