[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2019 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 21 /** 22 * @see https://www.w3.org/TR/webauthn/#sec-attested-credential-data 23 */ 24 class AttestedCredentialData implements JsonSerializable 25 { 26 /** 27 * @var UuidInterface 28 */ 29 private $aaguid; 30 31 /** 32 * @var string 33 */ 34 private $credentialId; 35 36 /** 37 * @var string|null 38 */ 39 private $credentialPublicKey; 40 41 public function __construct(UuidInterface $aaguid, string $credentialId, ?string $credentialPublicKey) 42 { 43 $this->aaguid = $aaguid; 44 $this->credentialId = $credentialId; 45 $this->credentialPublicKey = $credentialPublicKey; 46 } 47 48 public function getAaguid(): UuidInterface 49 { 50 return $this->aaguid; 51 } 52 53 public function getCredentialId(): string 54 { 55 return $this->credentialId; 56 } 57 58 public function getCredentialPublicKey(): ?string 59 { 60 return $this->credentialPublicKey; 61 } 62 63 public static function createFromArray(array $json): self 64 { 65 Assertion::keyExists($json, 'aaguid', 'Invalid input. "aaguid" is missing.'); 66 Assertion::keyExists($json, 'credentialId', 'Invalid input. "credentialId" is missing.'); 67 switch (true) { 68 case 36 === mb_strlen($json['aaguid'], '8bit'): 69 $uuid = Uuid::fromString($json['aaguid']); 70 break; 71 default: // Kept for compatibility with old format 72 $decoded = base64_decode($json['aaguid'], true); 73 Assertion::string($decoded, 'Unable to decode the data'); 74 $uuid = Uuid::fromBytes($decoded); 75 } 76 $credentialId = base64_decode($json['credentialId'], true); 77 Assertion::string($credentialId, 'Unable to decode the data'); 78 79 return new self( 80 $uuid, 81 $credentialId, 82 isset($json['credentialPublicKey']) ? base64_decode($json['credentialPublicKey'], true) : null 83 ); 84 } 85 86 public function jsonSerialize(): array 87 { 88 $result = [ 89 'aaguid' => $this->aaguid->toString(), 90 'credentialId' => base64_encode($this->credentialId), 91 ]; 92 if (null !== $this->credentialPublicKey) { 93 $result['credentialPublicKey'] = base64_encode($this->credentialPublicKey); 94 } 95 96 return $result; 97 } 98 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |