Class TOTPConfig.Builder

java.lang.Object
io.github.pratiyush.totp.TOTPConfig.Builder
Enclosing class:
TOTPConfig

public static final class TOTPConfig.Builder extends Object
Builder for creating TOTPConfig instances.

All setters validate their inputs immediately to fail fast on configuration errors.

  • Method Details

    • algorithm

      public TOTPConfig.Builder algorithm(Algorithm algorithm)
      Sets the HMAC algorithm.
      Parameters:
      algorithm - the algorithm (must not be null)
      Returns:
      this builder
      Throws:
      NullPointerException - if algorithm is null
    • digits

      public TOTPConfig.Builder digits(int 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

      public TOTPConfig.Builder period(Duration 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 null
      IllegalArgumentException - if period is out of range
    • periodSeconds

      public TOTPConfig.Builder periodSeconds(int seconds)
      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

      public TOTPConfig.Builder allowedDrift(int steps)
      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

      public TOTPConfig build()
      Builds the configuration.
      Returns:
      immutable configuration instance