PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.1.0
Defender Security – Malware Scanner, Login Security & Firewall v3.1.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / webauthn-lib / src / AuthenticatorSelectionCriteria.php

AuthenticatorSelectionCriteria.php in Defender Security – Malware Scanner, Login Security & Firewall 3.1.0, at vendor/web-auth/webauthn-lib/src/AuthenticatorSelectionCriteria.php

168 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Webauthn;
15
16 use Assert\Assertion;
17 use JsonSerializable;
18 use function Safe\json_decode;
19
20 class AuthenticatorSelectionCriteria implements JsonSerializable
21 {
22 public const AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE = null;
23 public const AUTHENTICATOR_ATTACHMENT_PLATFORM = 'platform';
24 public const AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM = 'cross-platform';
25
26 public const USER_VERIFICATION_REQUIREMENT_REQUIRED = 'required';
27 public const USER_VERIFICATION_REQUIREMENT_PREFERRED = 'preferred';
28 public const USER_VERIFICATION_REQUIREMENT_DISCOURAGED = 'discouraged';
29
30 public const RESIDENT_KEY_REQUIREMENT_NONE = null;
31 public const RESIDENT_KEY_REQUIREMENT_REQUIRED = 'required';
32 public const RESIDENT_KEY_REQUIREMENT_PREFERRED = 'preferred';
33 public const RESIDENT_KEY_REQUIREMENT_DISCOURAGED = 'discouraged';
34
35 /**
36 * @var string|null
37 */
38 private $authenticatorAttachment;
39
40 /**
41 * @var bool
42 */
43 private $requireResidentKey;
44
45 /**
46 * @var string
47 */
48 private $userVerification;
49
50 /**
51 * @var string|null
52 */
53 private $residentKey;
54
55 public function __construct(?string $authenticatorAttachment = null, ?bool $requireResidentKey = null, ?string $userVerification = null, ?string $residentKey = null)
56 {
57 if (null !== $authenticatorAttachment) {
58 @trigger_error('The argument "authenticatorAttachment" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "setAuthenticatorAttachment".', E_USER_DEPRECATED);
59 }
60 if (null !== $requireResidentKey) {
61 @trigger_error('The argument "requireResidentKey" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "setRequireResidentKey".', E_USER_DEPRECATED);
62 }
63 if (null !== $userVerification) {
64 @trigger_error('The argument "userVerification" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "setUserVerification".', E_USER_DEPRECATED);
65 }
66 if (null !== $residentKey) {
67 @trigger_error('The argument "residentKey" is deprecated since version 3.3 and will be removed in 4.0. Please use the method "setResidentKey".', E_USER_DEPRECATED);
68 }
69 $this->authenticatorAttachment = $authenticatorAttachment;
70 $this->requireResidentKey = $requireResidentKey ?? false;
71 $this->userVerification = $userVerification ?? self::USER_VERIFICATION_REQUIREMENT_PREFERRED;
72 $this->residentKey = $residentKey ?? self::RESIDENT_KEY_REQUIREMENT_NONE;
73 }
74
75 public static function create(): self
76 {
77 return new self();
78 }
79
80 public function setAuthenticatorAttachment(?string $authenticatorAttachment): self
81 {
82 $this->authenticatorAttachment = $authenticatorAttachment;
83
84 return $this;
85 }
86
87 public function setRequireResidentKey(bool $requireResidentKey): self
88 {
89 $this->requireResidentKey = $requireResidentKey;
90
91 return $this;
92 }
93
94 public function setUserVerification(string $userVerification): self
95 {
96 $this->userVerification = $userVerification;
97
98 return $this;
99 }
100
101 public function setResidentKey(?string $residentKey): self
102 {
103 $this->residentKey = $residentKey;
104
105 return $this;
106 }
107
108 public function getAuthenticatorAttachment(): ?string
109 {
110 return $this->authenticatorAttachment;
111 }
112
113 public function isRequireResidentKey(): bool
114 {
115 return $this->requireResidentKey;
116 }
117
118 public function getUserVerification(): string
119 {
120 return $this->userVerification;
121 }
122
123 public function getResidentKey(): ?string
124 {
125 return $this->residentKey;
126 }
127
128 public static function createFromString(string $data): self
129 {
130 $data = json_decode($data, true);
131 Assertion::isArray($data, 'Invalid data');
132
133 return self::createFromArray($data);
134 }
135
136 /**
137 * @param mixed[] $json
138 */
139 public static function createFromArray(array $json): self
140 {
141 return self::create()
142 ->setAuthenticatorAttachment($json['authenticatorAttachment'] ?? null)
143 ->setRequireResidentKey($json['requireResidentKey'] ?? false)
144 ->setUserVerification($json['userVerification'] ?? self::USER_VERIFICATION_REQUIREMENT_PREFERRED)
145 ->setResidentKey($json['residentKey'] ?? self::RESIDENT_KEY_REQUIREMENT_NONE)
146 ;
147 }
148
149 /**
150 * @return mixed[]
151 */
152 public function jsonSerialize(): array
153 {
154 $json = [
155 'requireResidentKey' => $this->requireResidentKey,
156 'userVerification' => $this->userVerification,
157 ];
158 if (null !== $this->authenticatorAttachment) {
159 $json['authenticatorAttachment'] = $this->authenticatorAttachment;
160 }
161 if (null !== $this->residentKey) {
162 $json['residentKey'] = $this->residentKey;
163 }
164
165 return $json;
166 }
167 }
168