From 30a9ae16321cc014f281e2cd8fb6ad295da9b4a4 Mon Sep 17 00:00:00 2001 From: TheArrayser Date: Sun, 18 Jun 2023 22:49:39 +0200 Subject: [PATCH] add documentation and fixed disagreement between docs and code --- .../cringe_authenticator_library/OTP.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cringe_studios/cringe_authenticator_library/OTP.java b/src/main/java/com/cringe_studios/cringe_authenticator_library/OTP.java index 9153b7a..22cf386 100644 --- a/src/main/java/com/cringe_studios/cringe_authenticator_library/OTP.java +++ b/src/main/java/com/cringe_studios/cringe_authenticator_library/OTP.java @@ -19,10 +19,10 @@ public abstract class OTP { this.secret = Base32.decode(nSecret); base32Secret = nSecret; type = nType; - algorithm = nAlgorithm; - digits = nDigits; + algorithm = (nAlgorithm == null) ? OTPAlgorithm.SHA1 : nAlgorithm; + digits = (nDigits <= 0) ? 6 : nDigits; counter = nCounter; - period = nPeriodInSeconds; + period = (nPeriodInSeconds <= 0) ? 30 : nPeriodInSeconds; checksum = nChecksum; } @@ -32,6 +32,18 @@ public abstract class OTP { //OTPType: required //period: optional (default 30) //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) { return type.instance(secret, algorithm, digits, counter, periodInSeconds, checksum); }