jchambers / java-otp

A one-time password (HOTP/TOTP) library for Java
MIT License
456 stars 122 forks source link

Use an unchecked exception for unsupported MAC algorithms #29

Closed jchambers closed 2 years ago

jchambers commented 3 years ago

This introduces a NoSuchAlgorithmRuntimeException to take the place of NoSuchAlgorithmException. The rationale is that, in virtually all cases, a NoSuchAlgorithmException is practically impossible because all JVMs are required to support SHA-1 and SHA-256. The one exception is SHA-512, which JVMs are not required to support (but most do).

Re-throwing NoSuchAlgorithmException as a NoSuchAlgorithmRuntimeException means that callers don't need to catch an exception that can never happen in most cases; in the one case where it can happen, we'll rely on the docs to warn callers that they should be on the lookout for a NoSuchAlgorithmRuntimeException.

My hope is that this is a worthwhile tradeoff in favor of API ergonomics, but I welcome feedback!