Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/AuthenticatorSelectionCriteria.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn;
6
7 use function in_array;
8 use InvalidArgumentException;
9
10 class AuthenticatorSelectionCriteria
11 {
12 final public const AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE = null;
13
14 final public const AUTHENTICATOR_ATTACHMENT_PLATFORM = 'platform';
15
16 final public const AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM = 'cross-platform';
17
18 final public const AUTHENTICATOR_ATTACHMENTS = [
19 self::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE,
20 self::AUTHENTICATOR_ATTACHMENT_PLATFORM,
21 self::AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
22 ];
23
24 final public const USER_VERIFICATION_REQUIREMENT_REQUIRED = 'required';
25
26 final public const USER_VERIFICATION_REQUIREMENT_PREFERRED = 'preferred';
27
28 final public const USER_VERIFICATION_REQUIREMENT_DISCOURAGED = 'discouraged';
29
30 final public const USER_VERIFICATION_REQUIREMENTS = [
31 self::USER_VERIFICATION_REQUIREMENT_REQUIRED,
32 self::USER_VERIFICATION_REQUIREMENT_PREFERRED,
33 self::USER_VERIFICATION_REQUIREMENT_DISCOURAGED,
34 ];
35
36 final public const RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE = null;
37
38 final public const RESIDENT_KEY_REQUIREMENT_REQUIRED = 'required';
39
40 final public const RESIDENT_KEY_REQUIREMENT_PREFERRED = 'preferred';
41
42 final public const RESIDENT_KEY_REQUIREMENT_DISCOURAGED = 'discouraged';
43
44 final public const RESIDENT_KEY_REQUIREMENTS = [
45 self::RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE,
46 self::RESIDENT_KEY_REQUIREMENT_REQUIRED,
47 self::RESIDENT_KEY_REQUIREMENT_PREFERRED,
48 self::RESIDENT_KEY_REQUIREMENT_DISCOURAGED,
49 ];
50
51 /**
52 * Legacy property for backward compatibility.
53 *
54 * requireResidentKey is based on residentKey for backward compatibility
55 * Per WebAuthn Level 3 spec: "Relying Parties SHOULD set it to true if, and only if, residentKey is set to required."
56 * Only set when residentKey is "required"; leave uninitialized otherwise
57 */
58 public readonly ?bool $requireResidentKey;
59
60 public function __construct(
61 public null|string $authenticatorAttachment = null,
62 public string $userVerification = self::USER_VERIFICATION_REQUIREMENT_PREFERRED,
63 public null|string $residentKey = self::RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE,
64 ) {
65 in_array($authenticatorAttachment, self::AUTHENTICATOR_ATTACHMENTS, true) || throw new InvalidArgumentException(
66 'Invalid authenticator attachment'
67 );
68 in_array($userVerification, self::USER_VERIFICATION_REQUIREMENTS, true) || throw new InvalidArgumentException(
69 'Invalid user verification'
70 );
71 in_array($residentKey, self::RESIDENT_KEY_REQUIREMENTS, true) || throw new InvalidArgumentException(
72 'Invalid resident key'
73 );
74
75 if ($residentKey === self::RESIDENT_KEY_REQUIREMENT_REQUIRED) {
76 $this->requireResidentKey = true;
77 } else {
78 $this->requireResidentKey = null;
79 }
80 }
81
82 public static function create(
83 ?string $authenticatorAttachment = null,
84 string $userVerification = self::USER_VERIFICATION_REQUIREMENT_PREFERRED,
85 null|string $residentKey = self::RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE,
86 ): self {
87 return new self($authenticatorAttachment, $userVerification, $residentKey);
88 }
89 }