| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Webauthn; |
| 6 | |
| 7 | use function strlen; |
| 8 | use Webauthn\Exception\InvalidDataException; |
| 9 | |
| 10 | class PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity |
| 11 | { |
| 12 | public readonly string $id; |
| 13 | |
| 14 | public function __construct( |
| 15 | string $name, |
| 16 | string $id, |
| 17 | public readonly string $displayName, |
| 18 | ?string $icon = null |
| 19 | ) { |
| 20 | parent::__construct('', $icon); |
| 21 | strlen($id) <= 64 || throw InvalidDataException::create($id, 'User ID max length is 64 bytes'); |
| 22 | $this->id = $id; |
| 23 | $this->name = $name; |
| 24 | } |
| 25 | |
| 26 | public static function create(string $name, string $id, string $displayName, ?string $icon = null): self |
| 27 | { |
| 28 | return new self($name, $id, $displayName, $icon); |
| 29 | } |
| 30 | } |