Package io.github.pratiyush.totp
Class TOTPConfig.Builder
java.lang.Object
io.github.pratiyush.totp.TOTPConfig.Builder
- Enclosing class:
TOTPConfig
Builder for creating
TOTPConfig instances.
All setters validate their inputs immediately to fail fast on configuration errors.
-
Method Summary
Modifier and TypeMethodDescriptionSets the HMAC algorithm.allowedDrift(int steps) Sets the allowed drift steps for verification.build()Builds the configuration.digits(int digits) Sets the number of digits in generated codes.Sets the time period for code validity.periodSeconds(int seconds) Sets the period in seconds.
-
Method Details
-
algorithm
Sets the HMAC algorithm.- Parameters:
algorithm- the algorithm (must not be null)- Returns:
- this builder
- Throws:
NullPointerException- if algorithm is null
-
digits
Sets the number of digits in generated codes.- Parameters:
digits- digit count (must be 6-8)- Returns:
- this builder
- Throws:
IllegalArgumentException- if digits is out of range
-
period
Sets the time period for code validity.- Parameters:
period- the period (must be 15-120 seconds)- Returns:
- this builder
- Throws:
NullPointerException- if period is nullIllegalArgumentException- if period is out of range
-
periodSeconds
Sets the period in seconds.- Parameters:
seconds- period in seconds (must be 15-120)- Returns:
- this builder
- Throws:
IllegalArgumentException- if seconds is out of range
-
allowedDrift
Sets the allowed drift steps for verification.A drift of 1 means codes from 1 step before and 1 step after the current time will be accepted (3 codes total).
- Parameters:
steps- allowed drift steps (must be 0-5)- Returns:
- this builder
- Throws:
IllegalArgumentException- if steps is out of range
-
build
Builds the configuration.- Returns:
- immutable configuration instance
-