| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\AttestationStatement; |
| 6 |
|
| 7 |
use function array_key_exists; |
| 8 |
use function sprintf; |
| 9 |
use Webauthn\Exception\InvalidDataException; |
| 10 |
use Webauthn\TrustPath\TrustPath; |
| 11 |
|
| 12 |
class AttestationStatement |
| 13 |
{ |
| 14 |
final public const TYPE_NONE = 'none'; |
| 15 |
|
| 16 |
final public const TYPE_BASIC = 'basic'; |
| 17 |
|
| 18 |
final public const TYPE_SELF = 'self'; |
| 19 |
|
| 20 |
final public const TYPE_ATTCA = 'attca'; |
| 21 |
|
| 22 |
final public const TYPE_ANONCA = 'anonca'; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function __construct( |
| 28 |
public readonly string $fmt, |
| 29 |
public readonly array $attStmt, |
| 30 |
public readonly string $type, |
| 31 |
public readonly TrustPath $trustPath |
| 32 |
) { |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public static function create(string $fmt, array $attStmt, string $type, TrustPath $trustPath): self |
| 39 |
{ |
| 40 |
return new self($fmt, $attStmt, $type, $trustPath); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static function createNone(string $fmt, array $attStmt, TrustPath $trustPath): self |
| 47 |
{ |
| 48 |
return self::create($fmt, $attStmt, self::TYPE_NONE, $trustPath); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static function createBasic(string $fmt, array $attStmt, TrustPath $trustPath): self |
| 55 |
{ |
| 56 |
return self::create($fmt, $attStmt, self::TYPE_BASIC, $trustPath); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static function createSelf(string $fmt, array $attStmt, TrustPath $trustPath): self |
| 63 |
{ |
| 64 |
return self::create($fmt, $attStmt, self::TYPE_SELF, $trustPath); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static function createAttCA(string $fmt, array $attStmt, TrustPath $trustPath): self |
| 71 |
{ |
| 72 |
return self::create($fmt, $attStmt, self::TYPE_ATTCA, $trustPath); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static function createAnonymizationCA(string $fmt, array $attStmt, TrustPath $trustPath): self |
| 79 |
{ |
| 80 |
return self::create($fmt, $attStmt, self::TYPE_ANONCA, $trustPath); |
| 81 |
} |
| 82 |
|
| 83 |
public function has(string $key): bool |
| 84 |
{ |
| 85 |
return array_key_exists($key, $this->attStmt); |
| 86 |
} |
| 87 |
|
| 88 |
public function get(string $key): mixed |
| 89 |
{ |
| 90 |
$this->has($key) || throw InvalidDataException::create($this->attStmt, sprintf( |
| 91 |
'The attestation statement has no key "%s".', |
| 92 |
$key |
| 93 |
)); |
| 94 |
|
| 95 |
return $this->attStmt[$key]; |
| 96 |
} |
| 97 |
} |