All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.turingcomplete.kotlinonetimepassword.HmacOneTimePasswordConfig.kt Maven / Gradle / Ivy

Go to download

A Kotlin one-time password library to generate "Google Authenticator", "Time-based One-time Password" (TOTP) and "HMAC-based One-time Password" (HOTP) codes based on RFC 4226 and 6238.

There is a newer version: 2.4.1
Show newest version
package dev.turingcomplete.kotlinonetimepassword

import java.lang.IllegalArgumentException

/**
 * The configuration for the [HmacOneTimePasswordGenerator].
 *
 * @property codeDigits the length of the generated code. The RFC 4226 requires
 *                      a code digits value between 6 and 8 to assure a good
 *                      security trade-off. However, this library does not set
 *                      any requirement for this property. But notice that through
 *                      the design of the algorithm the maximum code value is
 *                      2,147,483,647. Which means that a larger code digits value
 *                      than 10 just adds more trailing zeros to the code (and in
 *                      case of 10 digits the first number is always 0, 1 or 2).
 *
 * @property hmacAlgorithm the "keyed-hash message authentication code" algorithm
 *                         to use to generate the hash, from which the code is
 *                         extracted (see [HmacAlgorithm] for available algorithms).
 *
 * @throws IllegalArgumentException if `codeDigits` is negative.
 */
open class HmacOneTimePasswordConfig(var codeDigits: Int, var hmacAlgorithm: HmacAlgorithm) {
  init {
    require(codeDigits >= 0) { "Code digits must have a positive value." }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy