Skip to content
Merged
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
8 changes: 5 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ parameters:
- ./tests
excludePaths:
- var/
- templates/
- translations/

ignoreErrors:
- '#Attribute class Symfony\\Contracts\\Service\\Attribute\\Required does not exist#' # Not required
# Not required
- '#Attribute class Symfony\\Contracts\\Service\\Attribute\\Required does not exist#'

# Always set, as it's only NULL after zeroing, which happens later
- '#Parameter \#1 \$verifier of method Rollerworks\\Component\\SplitToken\\SplitToken\:\:hashVerifier\(\) expects string, string\|null given#'
6 changes: 5 additions & 1 deletion src/SplitToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class SplitToken
protected array $config = [];
private HiddenString $token;
private string $selector;
private string $verifier;
private ?string $verifier;
private ?string $verifierHash = null;
private ?\DateTimeImmutable $expiresAt = null;

Expand Down Expand Up @@ -203,6 +203,10 @@ final public function matches(?SplitTokenValueHolder $token): bool
return false;
}

if ($this->verifier === null) {
throw new \RuntimeException('matches() does not work with a SplitToken object when created with create(), use fromString() instead.');
}

return $this->verifyHash($token->verifierHash(), $this->verifier);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Argon2SplitTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ public function it_fails_when_creating_holder_with_string_constructed(): void
SplitToken::fromString(self::FULL_TOKEN)->toValueHolder();
}

#[Test]
public function it_fails_matches_when_just_created(): void
{
$splitToken = SplitToken::create(self::$randValue);

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('matches() does not work with a SplitToken object when created with create(), use fromString() instead.');

$splitToken->matches($splitToken->toValueHolder());
}

#[Test]
public function it_verifies_split_token(): void
{
Expand Down