Skip to content

Commit

Permalink
remove throws
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdan committed Mar 8, 2019
1 parent 00d1d00 commit 161a2b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,5 +1,8 @@
FusionAuth JWT Changes

Changes in 3.0.3
* Remove throws from OpenIDConnect utility methods

Changes in 3.0.2
* Add JWTUtils.decodePayload and decodeHeader as a utility to decode a JWT, this is an unsafe and should only be used for utility not to verify the JWT.

Expand Down
2 changes: 1 addition & 1 deletion build.savant
Expand Up @@ -18,7 +18,7 @@ savantVersion = "1.0.0"
jacksonVersion = "2.9.8"
jacksonAnnotationVersion = "2.9.6"

project(group: "io.fusionauth", name: "fusionauth-jwt", version: "3.0.2", licenses: ["ApacheV2_0"]) {
project(group: "io.fusionauth", name: "fusionauth-jwt", version: "3.0.3", licenses: ["ApacheV2_0"]) {

workflow {
standard()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>io.fusionauth</groupId>
<artifactId>fusionauth-jwt</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<packaging>jar</packaging>

<name>FusionAuth JWT</name>
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/io/fusionauth/jwt/OpenIDConnect.java
Expand Up @@ -38,9 +38,8 @@ public class OpenIDConnect {
* @param accessToken the ASCII form of the access token
* @param algorithm the algorithm to be used when encoding the Id Token
* @return a hash to be used as the <code>at_hash</code> claim in the Id Token claim payload
* @throws NoSuchAlgorithmException Thrown when no provider supports an implementation of the specified algorithm
*/
public static String at_hash(String accessToken, Algorithm algorithm) throws NoSuchAlgorithmException {
public static String at_hash(String accessToken, Algorithm algorithm) {
return generate_hash(accessToken, algorithm);
}

Expand All @@ -50,13 +49,12 @@ public static String at_hash(String accessToken, Algorithm algorithm) throws NoS
* @param authorizationCode the ASCII form of the authorization code
* @param algorithm the algorithm to be used when encoding the Id Token
* @return a hash to be used as the <code>c_hash</code> claim in the Id Token claim payload
* @throws NoSuchAlgorithmException Thrown when no provider supports an implementation of the specified algorithm
*/
public static String c_hash(String authorizationCode, Algorithm algorithm) throws NoSuchAlgorithmException {
public static String c_hash(String authorizationCode, Algorithm algorithm) {
return generate_hash(authorizationCode, algorithm);
}

private static String generate_hash(String string, Algorithm algorithm) throws NoSuchAlgorithmException {
private static String generate_hash(String string, Algorithm algorithm) {
Objects.requireNonNull(string);
Objects.requireNonNull(algorithm);

Expand All @@ -66,19 +64,19 @@ private static String generate_hash(String string, Algorithm algorithm) throws N
case ES256:
case HS256:
case RS256:
messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest = getDigest("SHA-256");
leftMostBits = 128;
break;
case ES384:
case HS384:
case RS384:
messageDigest = MessageDigest.getInstance("SHA-384");
messageDigest = getDigest("SHA-384");
leftMostBits = 192;
break;
case ES512:
case HS512:
case RS512:
messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest = getDigest("SHA-512");
leftMostBits = 256;
break;
default:
Expand All @@ -94,4 +92,12 @@ private static String generate_hash(String string, Algorithm algorithm) throws N

return new String(Base64.getUrlEncoder().withoutPadding().encode(leftMostBytes));
}

private static MessageDigest getDigest(String digest) {
try {
return MessageDigest.getInstance(digest);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 161a2b2

Please sign in to comment.