diff --git a/src/HOTP.php b/src/HOTP.php index e6bea73..adcbdfa 100644 --- a/src/HOTP.php +++ b/src/HOTP.php @@ -41,9 +41,9 @@ public static function createFromSecret(string $secret): self return $htop; } - public static function generate(): self + public static function generate(int $secretSize = null): self { - return self::createFromSecret(self::generateSecret()); + return self::createFromSecret(self::generateSecret($secretSize)); } public function getCounter(): int diff --git a/src/OTP.php b/src/OTP.php index 49e1730..0f981d2 100644 --- a/src/OTP.php +++ b/src/OTP.php @@ -43,9 +43,9 @@ public function at(int $input): string /** * @return non-empty-string */ - final protected static function generateSecret(): string + final protected static function generateSecret(int $secretSize = null): string { - return Base32::encodeUpper(random_bytes(self::DEFAULT_SECRET_SIZE)); + return Base32::encodeUpper(random_bytes($secretSize ?? self::DEFAULT_SECRET_SIZE)); } /** diff --git a/src/TOTP.php b/src/TOTP.php index 6bc87ee..beb1611 100644 --- a/src/TOTP.php +++ b/src/TOTP.php @@ -62,9 +62,9 @@ public static function createFromSecret(string $secret, ?ClockInterface $clock = return $totp; } - public static function generate(?ClockInterface $clock = null): self + public static function generate(?ClockInterface $clock = null, int $secretSize = null): self { - return self::createFromSecret(self::generateSecret(), $clock); + return self::createFromSecret(self::generateSecret($secretSize), $clock); } public function getPeriod(): int