| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
/* |
| 6 |
* The MIT License (MIT) |
| 7 |
* |
| 8 |
* Copyright (c) 2014-2021 Spomky-Labs |
| 9 |
* |
| 10 |
* This software may be modified and distributed under the terms |
| 11 |
* of the MIT license. See the LICENSE file for details. |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace WP_DEFENDER_VENDOR\Webauthn; |
| 15 |
|
| 16 |
use JsonSerializable; |
| 17 |
use WP_DEFENDER_VENDOR\Webauthn\AuthenticationExtensions\AuthenticationExtension; |
| 18 |
use WP_DEFENDER_VENDOR\Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs; |
| 19 |
|
| 20 |
abstract class PublicKeyCredentialOptions implements JsonSerializable |
| 21 |
{ |
| 22 |
/** |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
protected $challenge; |
| 26 |
|
| 27 |
/** |
| 28 |
* @var int|null |
| 29 |
*/ |
| 30 |
protected $timeout; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var AuthenticationExtensionsClientInputs |
| 34 |
*/ |
| 35 |
protected $extensions; |
| 36 |
|
| 37 |
public function __construct(string $challenge, ?int $timeout = null, ?AuthenticationExtensionsClientInputs $extensions = null) |
| 38 |
{ |
| 39 |
if (null !== $timeout) { |
| 40 |
@trigger_error('The argument "timeout" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "setTimeout".', E_USER_DEPRECATED); |
| 41 |
} |
| 42 |
if (null !== $extensions) { |
| 43 |
@trigger_error('The argument "extensions" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "addExtension" or "addExtensions".', E_USER_DEPRECATED); |
| 44 |
} |
| 45 |
$this->challenge = $challenge; |
| 46 |
$this->setTimeout($timeout); |
| 47 |
$this->extensions = $extensions ?? new AuthenticationExtensionsClientInputs(); |
| 48 |
} |
| 49 |
|
| 50 |
public function setTimeout(?int $timeout): self |
| 51 |
{ |
| 52 |
$this->timeout = $timeout; |
| 53 |
|
| 54 |
return $this; |
| 55 |
} |
| 56 |
|
| 57 |
public function addExtension(AuthenticationExtension $extension): self |
| 58 |
{ |
| 59 |
$this->extensions->add($extension); |
| 60 |
|
| 61 |
return $this; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @param AuthenticationExtension[] $extensions |
| 66 |
*/ |
| 67 |
public function addExtensions(array $extensions): self |
| 68 |
{ |
| 69 |
foreach ($extensions as $extension) { |
| 70 |
$this->addExtension($extension); |
| 71 |
} |
| 72 |
|
| 73 |
return $this; |
| 74 |
} |
| 75 |
|
| 76 |
public function setExtensions(AuthenticationExtensionsClientInputs $extensions): self |
| 77 |
{ |
| 78 |
$this->extensions = $extensions; |
| 79 |
|
| 80 |
return $this; |
| 81 |
} |
| 82 |
|
| 83 |
public function getChallenge(): string |
| 84 |
{ |
| 85 |
return $this->challenge; |
| 86 |
} |
| 87 |
|
| 88 |
public function getTimeout(): ?int |
| 89 |
{ |
| 90 |
return $this->timeout; |
| 91 |
} |
| 92 |
|
| 93 |
public function getExtensions(): AuthenticationExtensionsClientInputs |
| 94 |
{ |
| 95 |
return $this->extensions; |
| 96 |
} |
| 97 |
|
| 98 |
abstract public static function createFromString(string $data): self; |
| 99 |
|
| 100 |
/** |
| 101 |
* @param mixed[] $json |
| 102 |
*/ |
| 103 |
abstract public static function createFromArray(array $json): self; |
| 104 |
} |
| 105 |
|