| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\AuthenticationExtensions; |
| 6 |
|
| 7 |
use function array_key_exists; |
| 8 |
use ParagonIE\ConstantTime\Base64UrlSafe; |
| 9 |
|
| 10 |
final class PseudoRandomFunctionInputExtensionBuilder |
| 11 |
{ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
private array $values = []; |
| 16 |
|
| 17 |
private function __construct() |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
public static function create(): self |
| 22 |
{ |
| 23 |
return new self(); |
| 24 |
} |
| 25 |
|
| 26 |
public function withInputs(string $first, null|string $second = null): self |
| 27 |
{ |
| 28 |
$eval = [ |
| 29 |
'first' => Base64UrlSafe::encodeUnpadded($first), |
| 30 |
]; |
| 31 |
if ($second !== null) { |
| 32 |
$eval['second'] = Base64UrlSafe::encodeUnpadded($second); |
| 33 |
} |
| 34 |
$this->values['eval'] = $eval; |
| 35 |
|
| 36 |
return $this; |
| 37 |
} |
| 38 |
|
| 39 |
public function withCredentialInputs(string $credentialId, string $first, null|string $second = null): self |
| 40 |
{ |
| 41 |
$eval = [ |
| 42 |
'first' => Base64UrlSafe::encodeUnpadded($first), |
| 43 |
]; |
| 44 |
if ($second !== null) { |
| 45 |
$eval['second'] = Base64UrlSafe::encodeUnpadded($second); |
| 46 |
} |
| 47 |
if (! array_key_exists('evalByCredential', $this->values)) { |
| 48 |
$this->values['evalByCredential'] = []; |
| 49 |
} |
| 50 |
$this->values['evalByCredential'][$credentialId] = $eval; |
| 51 |
|
| 52 |
return $this; |
| 53 |
} |
| 54 |
|
| 55 |
public function build(): PseudoRandomFunctionInputExtension |
| 56 |
{ |
| 57 |
return new PseudoRandomFunctionInputExtension('prf', $this->values); |
| 58 |
} |
| 59 |
} |