add documentation and fixed disagreement between docs and code

This commit is contained in:
TheArrayser 2023-06-18 22:49:39 +02:00
parent 3542c7aed3
commit 30a9ae1632

View File

@ -19,10 +19,10 @@ public abstract class OTP {
this.secret = Base32.decode(nSecret); this.secret = Base32.decode(nSecret);
base32Secret = nSecret; base32Secret = nSecret;
type = nType; type = nType;
algorithm = nAlgorithm; algorithm = (nAlgorithm == null) ? OTPAlgorithm.SHA1 : nAlgorithm;
digits = nDigits; digits = (nDigits <= 0) ? 6 : nDigits;
counter = nCounter; counter = nCounter;
period = nPeriodInSeconds; period = (nPeriodInSeconds <= 0) ? 30 : nPeriodInSeconds;
checksum = nChecksum; checksum = nChecksum;
} }
@ -32,6 +32,18 @@ public abstract class OTP {
//OTPType: required //OTPType: required
//period: optional (default 30) //period: optional (default 30)
//counter: required if hotp //counter: required if hotp
/**
*
* @param type REQUIRED: the type of the OTP (HTOP or TOTP)
* @param secret REQUIRED: the secret, base32 encoded
* @param algorithm OPTIONAL (default SHA1) the hash algorithm to use (SHA1 SHA224 SHA256 SHA384 SHA512)
* @param digits OPTIONAL (Default 6) how many digits to calculate
* @param counter REQUIRED if HOTP, otherwise meaningless. The initial counter for HOTP (eg 21, if user reloaded counter 21 times)
* @param periodInSeconds OPTIONAL (default 30) for TOTP, the refresh rate of the TOTP
* @param checksum OPTIONAL: appends a checksum digit to the end of the string
* @return returns a String containing the OTP Digits and the optional checksum at the end
*/
public static OTP createNewOTP(OTPType type, String secret, OTPAlgorithm algorithm, int digits, long counter, long periodInSeconds, boolean checksum) { public static OTP createNewOTP(OTPType type, String secret, OTPAlgorithm algorithm, int digits, long counter, long periodInSeconds, boolean checksum) {
return type.instance(secret, algorithm, digits, counter, periodInSeconds, checksum); return type.instance(secret, algorithm, digits, counter, periodInSeconds, checksum);
} }