Skip to content

Commit a8dc8dd

Browse files
committed
Rename NoSuchAlgorithmRuntimeException to UncheckedNoSuchAlgorithmException
1 parent 3349eb5 commit a8dc8dd

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

src/main/java/com/eatthepath/otp/HmacOneTimePasswordGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public HmacOneTimePasswordGenerator(final int passwordLength) {
8888
* HOTP only allows for {@value com.eatthepath.otp.HmacOneTimePasswordGenerator#HOTP_HMAC_ALGORITHM}, but derived
8989
* standards like TOTP may allow for other algorithms
9090
*
91-
* @throws NoSuchAlgorithmRuntimeException if the given algorithm is not supported by the underlying JRE
91+
* @throws UncheckedNoSuchAlgorithmException if the given algorithm is not supported by the underlying JRE
9292
*/
93-
HmacOneTimePasswordGenerator(final int passwordLength, final String algorithm) throws NoSuchAlgorithmRuntimeException {
93+
HmacOneTimePasswordGenerator(final int passwordLength, final String algorithm) throws UncheckedNoSuchAlgorithmException {
9494
try {
9595
this.mac = Mac.getInstance(algorithm);
9696
} catch (final NoSuchAlgorithmException e) {
97-
throw new NoSuchAlgorithmRuntimeException(e);
97+
throw new UncheckedNoSuchAlgorithmException(e);
9898
}
9999

100100
switch (passwordLength) {

src/main/java/com/eatthepath/otp/TimeBasedOneTimePasswordGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public TimeBasedOneTimePasswordGenerator(final Duration timeStep, final int pass
108108
* for {@value #TOTP_ALGORITHM_HMAC_SHA1}, {@value #TOTP_ALGORITHM_HMAC_SHA256}, and
109109
* {@value #TOTP_ALGORITHM_HMAC_SHA512}
110110
*
111-
* @throws NoSuchAlgorithmRuntimeException if the given algorithm is {@value #TOTP_ALGORITHM_HMAC_SHA512} and the
111+
* @throws UncheckedNoSuchAlgorithmException if the given algorithm is {@value #TOTP_ALGORITHM_HMAC_SHA512} and the
112112
* JVM does not support that algorithm; all JVMs are required to support {@value #TOTP_ALGORITHM_HMAC_SHA1} and
113113
* {@value #TOTP_ALGORITHM_HMAC_SHA256}, but are not required to support {@value #TOTP_ALGORITHM_HMAC_SHA512}
114114
*
@@ -117,7 +117,7 @@ public TimeBasedOneTimePasswordGenerator(final Duration timeStep, final int pass
117117
* @see #TOTP_ALGORITHM_HMAC_SHA512
118118
*/
119119
public TimeBasedOneTimePasswordGenerator(final Duration timeStep, final int passwordLength, final String algorithm)
120-
throws NoSuchAlgorithmRuntimeException {
120+
throws UncheckedNoSuchAlgorithmException {
121121

122122
this.hotp = new HmacOneTimePasswordGenerator(passwordLength, algorithm);
123123
this.timeStep = timeStep;

src/main/java/com/eatthepath/otp/NoSuchAlgorithmRuntimeException.java renamed to src/main/java/com/eatthepath/otp/UncheckedNoSuchAlgorithmException.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
import java.security.NoSuchAlgorithmException;
44

55
/**
6-
* A runtime exception that indicates that a requested MAC algorithm is not supported by the JVM.
6+
* Wraps a {@link NoSuchAlgorithmException} with an unchecked exception.
77
*
88
* @author <a href="https://github.com/jchambers">Jon Chambers</a>
99
*/
10-
public class NoSuchAlgorithmRuntimeException extends RuntimeException {
10+
public class UncheckedNoSuchAlgorithmException extends RuntimeException {
1111

12-
NoSuchAlgorithmRuntimeException(final NoSuchAlgorithmException e) {
13-
super(e);
12+
/**
13+
* Constructs a new unchecked {@code NoSuchAlgorithmException} instance.
14+
*
15+
* @param cause the underlying {@code NoSuchAlgorithmException}
16+
*/
17+
UncheckedNoSuchAlgorithmException(final NoSuchAlgorithmException cause) {
18+
super(cause);
1419
}
1520

1621
/**

src/test/java/com/eatthepath/otp/HmacOneTimePasswordGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void testHmacOneTimePasswordGeneratorWithLongPasswordLength() {
5353

5454
@Test
5555
void testHmacOneTimePasswordGeneratorWithBogusAlgorithm() {
56-
assertThrows(NoSuchAlgorithmRuntimeException.class, () ->
56+
assertThrows(UncheckedNoSuchAlgorithmException.class, () ->
5757
new HmacOneTimePasswordGenerator(6, "Definitely not a real algorithm"));
5858
}
5959

src/test/java/com/eatthepath/otp/TimeBasedOneTimePasswordGeneratorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,10 @@ private static Stream<Arguments> argumentsForTestGenerateOneTimePasswordStringLo
193193
}
194194

195195
private static void assumeAlgorithmSupported(final String algorithm) {
196-
boolean algorithmSupported;
196+
boolean algorithmSupported = true;
197197

198198
try {
199199
Mac.getInstance(algorithm);
200-
algorithmSupported = true;
201200
} catch (final NoSuchAlgorithmException e) {
202201
algorithmSupported = false;
203202
}

0 commit comments

Comments
 (0)