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
13 changes: 7 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
php-version:
- '8.2'
- '8.3'

steps:
-
Expand Down Expand Up @@ -103,20 +103,21 @@ jobs:
strategy:
matrix:
include:
-
php-version: '8.2'
composer-options: '--prefer-stable'
symfony-version: '6.3'
-
php-version: '8.2'
composer-options: '--prefer-stable'
symfony-version: '^6.4'

-
php-version: '8.2'
php-version: '8.3'
composer-options: '--prefer-stable'
symfony-version: '^7.0'

-
php-version: '8.4'
composer-options: '--prefer-stable'
symfony-version: '^7.2'

steps:
-
name: 'Check out'
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"homepage": "https://rollerworks.github.io",
"require": {
"php": ">=8.2",
"paragonie/constant_time_encoding": "^2.6",
"paragonie/constant_time_encoding": "^2.6 || ^3.0",
"paragonie/hidden-string": "^2.0",
"psr/clock": "^1.0"
},
"require-dev": {
"doctrine/instantiator": "^2.0",
"phpunit/phpunit": "^10.4",
"rollerscapes/standards": "^1.0",
"symfony/clock": "^6.3"
"symfony/clock": "^6.3 || ^7.2"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractSplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class AbstractSplitTokenFactory implements SplitTokenFactory
private ?\DateInterval $defaultLifeTime = null;
private ?ClockInterface $clock;

public function __construct(\DateInterval | string $defaultLifeTime = null)
public function __construct(\DateInterval | string | null $defaultLifeTime = null)
{
if (\is_string($defaultLifeTime)) {
$defaultLifeTime = new \DateInterval($defaultLifeTime);
Expand All @@ -33,7 +33,7 @@ public function setClock(ClockInterface $clock): void
$this->clock = $clock;
}

final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval $expiration = null): ?\DateTimeImmutable
final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval | null $expiration = null): ?\DateTimeImmutable
{
if ($expiration instanceof \DateTimeImmutable) {
return $expiration;
Expand Down
4 changes: 2 additions & 2 deletions src/Argon2SplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
final class Argon2SplitTokenFactory extends AbstractSplitTokenFactory
{
/** @param array<string, int> $config */
public function __construct(private array $config = [], \DateInterval | string $defaultLifeTime = null)
public function __construct(private array $config = [], \DateInterval | string | null $defaultLifeTime = null)
{
parent::__construct($defaultLifeTime);
}

public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken
{
$splitToken = Argon2SplitToken::create(
// DO NOT ENCODE HERE (always provide as raw binary)!
Expand Down
4 changes: 2 additions & 2 deletions src/FakeSplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public static function randomInstance(): self
return new self(random_bytes(FakeSplitToken::TOKEN_DATA_LENGTH));
}

public function __construct(string $randomValue = null, \DateInterval | string $defaultLifeTime = null)
public function __construct(?string $randomValue = null, \DateInterval | string | null $defaultLifeTime = null)
{
parent::__construct($defaultLifeTime);

$this->randomValue = $randomValue ?? ((string) hex2bin('d7351e5d4bebe0b2b298034107f6cb12a88fe463ebf8f85afce47a38e9d5d68f15cbfad6843a3128d22d'));
}

public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken
{
return FakeSplitToken::create(new HiddenString($this->randomValue, false, true))
->expireAt($this->getExpirationTimestamp($expiresAt));
Expand Down
4 changes: 2 additions & 2 deletions src/SplitToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

if (Binary::safeStrlen($bytesString) !== self::TOKEN_DATA_LENGTH) {
// Don't zero memory as the value is invalid.
throw new \RuntimeException(sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH));
throw new \RuntimeException(\sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH));
}

$selector = Base64UrlSafe::encode(Binary::safeSubstr($bytesString, 0, self::SELECTOR_BYTES));
Expand All @@ -131,13 +131,13 @@

$instance->verifierHash = $instance->hashVerifier($instance->verifier);

sodium_memzero($instance->verifier);

Check failure on line 134 in src/SplitToken.php

View workflow job for this annotation

GitHub Actions / PhpStan (8.3)

Property Rollerworks\Component\SplitToken\SplitToken::$verifier (string) does not accept null.
sodium_memzero($bytesString);

return $instance;
}

public function expireAt(\DateTimeImmutable $expiresAt = null): static
public function expireAt(?\DateTimeImmutable $expiresAt = null): static
{
$instance = clone $this;
$instance->expiresAt = $expiresAt;
Expand Down
2 changes: 1 addition & 1 deletion src/SplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function setClock(ClockInterface $clock): void;
*
* @see HiddenString
*/
public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken;
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken;

/**
* Recreates a SplitToken object from a token-string
Expand Down
6 changes: 3 additions & 3 deletions src/SplitTokenValueHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ final class SplitTokenValueHolder
private ?string $verifierHash = null;
private ?\DateTimeImmutable $expiresAt = null;
/** @var array<string, scalar> */
private array $metadata = [];
private ?array $metadata = [];

/** @param array<string, scalar> $metadata */
public function __construct(string $selector, string $verifierHash, \DateTimeImmutable $expiresAt = null, array $metadata = [])
public function __construct(string $selector, string $verifierHash, ?\DateTimeImmutable $expiresAt = null, array $metadata = [])
{
$this->selector = $selector;
$this->verifierHash = $verifierHash;
Expand Down Expand Up @@ -100,7 +100,7 @@ public function metadata(): array
return $this->metadata ?? [];
}

public function isExpired(\DateTimeImmutable $now = null): bool
public function isExpired(?\DateTimeImmutable $now = null): bool
{
if ($this->expiresAt === null) {
return false;
Expand Down
4 changes: 3 additions & 1 deletion tests/Argon2SplitTokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public function it_creates_from_stringable_object(): void
$splitToken = $factory->generate();

$stringObj = new class($splitToken->token()->getString()) implements \Stringable {
public function __construct(private string $value) {}
public function __construct(private string $value)
{
}

public function __toString(): string
{
Expand Down
7 changes: 5 additions & 2 deletions tests/FakeSplitTokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace Rollerworks\Component\SplitToken\Tests;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Rollerworks\Component\SplitToken\FakeSplitTokenFactory;
Expand Down Expand Up @@ -120,8 +122,9 @@ public function it_creates_from_stringable_object(): void
$stringObj = new class($splitToken->token()->getString()) implements \Stringable {
public function __construct(
#[\SensitiveParameter]
private string $value
) {}
private string $value,
) {
}

public function __toString(): string
{
Expand Down
Loading