PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.1
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 / AttestedCredentialData.php

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

114 lines 2.8 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 Ramsey\Uuid\Uuid;
19 use Ramsey\Uuid\UuidInterface;
20 use function Safe\base64_decode;
21
22 /**
23 * @see https://www.w3.org/TR/webauthn/#sec-attested-credential-data
24 */
25 class AttestedCredentialData implements JsonSerializable
26 {
27 /**
28 * @var UuidInterface
29 */
30 private $aaguid;
31
32 /**
33 * @var string
34 */
35 private $credentialId;
36
37 /**
38 * @var string|null
39 */
40 private $credentialPublicKey;
41
42 public function __construct(UuidInterface $aaguid, string $credentialId, ?string $credentialPublicKey)
43 {
44 $this->aaguid = $aaguid;
45 $this->credentialId = $credentialId;
46 $this->credentialPublicKey = $credentialPublicKey;
47 }
48
49 public function getAaguid(): UuidInterface
50 {
51 return $this->aaguid;
52 }
53
54 public function setAaguid(UuidInterface $aaguid): void
55 {
56 $this->aaguid = $aaguid;
57 }
58
59 public function getCredentialId(): string
60 {
61 return $this->credentialId;
62 }
63
64 public function getCredentialPublicKey(): ?string
65 {
66 return $this->credentialPublicKey;
67 }
68
69 /**
70 * @param mixed[] $json
71 */
72 public static function createFromArray(array $json): self
73 {
74 Assertion::keyExists($json, 'aaguid', 'Invalid input. "aaguid" is missing.');
75 Assertion::keyExists($json, 'credentialId', 'Invalid input. "credentialId" is missing.');
76 switch (true) {
77 case 36 === mb_strlen($json['aaguid'], '8bit'):
78 $uuid = Uuid::fromString($json['aaguid']);
79 break;
80 default: // Kept for compatibility with old format
81 $decoded = base64_decode($json['aaguid'], true);
82 $uuid = Uuid::fromBytes($decoded);
83 }
84 $credentialId = base64_decode($json['credentialId'], true);
85
86 $credentialPublicKey = null;
87 if (isset($json['credentialPublicKey'])) {
88 $credentialPublicKey = base64_decode($json['credentialPublicKey'], true);
89 }
90
91 return new self(
92 $uuid,
93 $credentialId,
94 $credentialPublicKey
95 );
96 }
97
98 /**
99 * @return mixed[]
100 */
101 public function jsonSerialize(): array
102 {
103 $result = [
104 'aaguid' => $this->aaguid->toString(),
105 'credentialId' => base64_encode($this->credentialId),
106 ];
107 if (null !== $this->credentialPublicKey) {
108 $result['credentialPublicKey'] = base64_encode($this->credentialPublicKey);
109 }
110
111 return $result;
112 }
113 }
114