Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing a $secretSize when generating a secret #204

Open
wants to merge 1 commit into
base: 11.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/HOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/OTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down