PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.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 / lib / packages / Webauthn / PublicKeyCredentialParameters.php

PublicKeyCredentialParameters.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Webauthn/PublicKeyCredentialParameters.php

83 lines 1.7 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 WP_DEFENDER_VENDOR\Webauthn;
15
16 use WP_DEFENDER_VENDOR\Assert\Assertion;
17 use JsonSerializable;
18 use function WP_DEFENDER_VENDOR\Safe\json_decode;
19
20 class PublicKeyCredentialParameters implements JsonSerializable
21 {
22 /**
23 * @var string
24 */
25 private $type;
26
27 /**
28 * @var int
29 */
30 private $alg;
31
32 public function __construct(string $type, int $alg)
33 {
34 $this->type = $type;
35 $this->alg = $alg;
36 }
37
38 public function getType(): string
39 {
40 return $this->type;
41 }
42
43 public function getAlg(): int
44 {
45 return $this->alg;
46 }
47
48 public static function createFromString(string $data): self
49 {
50 $data = json_decode($data, true);
51 Assertion::isArray($data, 'Invalid data');
52
53 return self::createFromArray($data);
54 }
55
56 /**
57 * @param mixed[] $json
58 */
59 public static function createFromArray(array $json): self
60 {
61 Assertion::keyExists($json, 'type', 'Invalid input. "type" is missing.');
62 Assertion::string($json['type'], 'Invalid input. "type" is not a string.');
63 Assertion::keyExists($json, 'alg', 'Invalid input. "alg" is missing.');
64 Assertion::integer($json['alg'], 'Invalid input. "alg" is not an integer.');
65
66 return new self(
67 $json['type'],
68 $json['alg']
69 );
70 }
71
72 /**
73 * @return mixed[]
74 */
75 public function jsonSerialize(): array
76 {
77 return [
78 'type' => $this->type,
79 'alg' => $this->alg,
80 ];
81 }
82 }
83