Package io.github.pratiyush.totp
Class TOTPException
java.lang.Object
java.lang.Throwable
java.lang.Exception
io.github.pratiyush.totp.TOTPException
- All Implemented Interfaces:
Serializable
Exception thrown for TOTP-related errors.
This is a checked exception to ensure callers explicitly handle error cases. The exception is designed to prevent accidental leakage of sensitive information such as secrets or internal state.
Error Codes
Each exception includes an TOTPException.ErrorCode for programmatic error handling:
TOTPException.ErrorCode.INVALID_SECRET- Secret is null, empty, or malformedTOTPException.ErrorCode.INVALID_CODE- Code format is invalidTOTPException.ErrorCode.INVALID_CONFIG- Configuration parameters are invalidTOTPException.ErrorCode.HMAC_ERROR- HMAC computation failedTOTPException.ErrorCode.QR_GENERATION_ERROR- QR code generation failedTOTPException.ErrorCode.INTERNAL_ERROR- Unexpected internal error
Security Note
Exception messages are sanitized to never include secrets or sensitive data. Always use the provided factory methods rather than constructing exceptions directly.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumError codes for programmatic error handling. -
Method Summary
Modifier and TypeMethodDescriptionReturns the error code for this exception.static TOTPExceptionCreates an exception for HMAC errors.static TOTPExceptioninternalError(String message, Throwable cause) Creates an exception for internal errors.static TOTPExceptioninvalidCode(String reason) Creates an exception for invalid codes.static TOTPExceptioninvalidConfig(String reason) Creates an exception for invalid configuration.static TOTPExceptioninvalidSecret(String reason) Creates an exception for invalid secrets.static TOTPExceptionqrGenerationError(Throwable cause) Creates an exception for QR generation errors.toString()Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Method Details
-
getErrorCode
Returns the error code for this exception.- Returns:
- the error code, never null
-
invalidSecret
Creates an exception for invalid secrets.- Parameters:
reason- the reason the secret is invalid (no sensitive data!)- Returns:
- new exception
-
invalidCode
Creates an exception for invalid codes.- Parameters:
reason- the reason the code is invalid- Returns:
- new exception
-
invalidConfig
Creates an exception for invalid configuration.- Parameters:
reason- the reason the configuration is invalid- Returns:
- new exception
-
hmacError
Creates an exception for HMAC errors.- Parameters:
cause- the underlying cause- Returns:
- new exception
-
qrGenerationError
Creates an exception for QR generation errors.- Parameters:
cause- the underlying cause- Returns:
- new exception
-
internalError
Creates an exception for internal errors.- Parameters:
message- the error messagecause- the underlying cause- Returns:
- new exception
-
toString
-