| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn; |
| 6 |
|
| 7 |
use function ord; |
| 8 |
use Webauthn\AuthenticationExtensions\AuthenticationExtensions; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class AuthenticatorData |
| 15 |
{ |
| 16 |
final public const FLAG_UP = 0b00000001; |
| 17 |
|
| 18 |
final public const FLAG_RFU1 = 0b00000010; |
| 19 |
|
| 20 |
final public const FLAG_UV = 0b00000100; |
| 21 |
|
| 22 |
final public const FLAG_BE = 0b00001000; |
| 23 |
|
| 24 |
final public const FLAG_BS = 0b00010000; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
final public const FLAG_RFU2 = 0b00111000; |
| 30 |
|
| 31 |
final public const FLAG_AT = 0b01000000; |
| 32 |
|
| 33 |
final public const FLAG_ED = 0b10000000; |
| 34 |
|
| 35 |
public function __construct( |
| 36 |
public readonly string $authData, |
| 37 |
public readonly string $rpIdHash, |
| 38 |
public readonly string $flags, |
| 39 |
public readonly int $signCount, |
| 40 |
public readonly null|AttestedCredentialData $attestedCredentialData, |
| 41 |
public readonly null|AuthenticationExtensions $extensions |
| 42 |
) { |
| 43 |
} |
| 44 |
|
| 45 |
public static function create( |
| 46 |
string $authData, |
| 47 |
string $rpIdHash, |
| 48 |
string $flags, |
| 49 |
int $signCount, |
| 50 |
null|AttestedCredentialData $attestedCredentialData = null, |
| 51 |
null|AuthenticationExtensions $extensions = null |
| 52 |
): self { |
| 53 |
return new self($authData, $rpIdHash, $flags, $signCount, $attestedCredentialData, $extensions); |
| 54 |
} |
| 55 |
|
| 56 |
public function isUserPresent(): bool |
| 57 |
{ |
| 58 |
return 0 !== (ord($this->flags) & self::FLAG_UP); |
| 59 |
} |
| 60 |
|
| 61 |
public function isUserVerified(): bool |
| 62 |
{ |
| 63 |
return 0 !== (ord($this->flags) & self::FLAG_UV); |
| 64 |
} |
| 65 |
|
| 66 |
public function isBackupEligible(): bool |
| 67 |
{ |
| 68 |
return 0 !== (ord($this->flags) & self::FLAG_BE); |
| 69 |
} |
| 70 |
|
| 71 |
public function isBackedUp(): bool |
| 72 |
{ |
| 73 |
return 0 !== (ord($this->flags) & self::FLAG_BS); |
| 74 |
} |
| 75 |
|
| 76 |
public function hasAttestedCredentialData(): bool |
| 77 |
{ |
| 78 |
return 0 !== (ord($this->flags) & self::FLAG_AT); |
| 79 |
} |
| 80 |
|
| 81 |
public function hasExtensions(): bool |
| 82 |
{ |
| 83 |
return 0 !== (ord($this->flags) & self::FLAG_ED); |
| 84 |
} |
| 85 |
|
| 86 |
public function getReservedForFutureUse1(): int |
| 87 |
{ |
| 88 |
return ord($this->flags) & self::FLAG_RFU1; |
| 89 |
} |
| 90 |
|
| 91 |
public function getReservedForFutureUse2(): int |
| 92 |
{ |
| 93 |
return ord($this->flags) & self::FLAG_RFU2; |
| 94 |
} |
| 95 |
} |