| 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\MetadataService; |
| 15 |
|
| 16 |
use function Safe\base64_decode; |
| 17 |
use function Safe\json_decode; |
| 18 |
|
| 19 |
class SingleMetadata |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @var MetadataStatement |
| 23 |
*/ |
| 24 |
private $statement; |
| 25 |
/** |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
private $data; |
| 29 |
/** |
| 30 |
* @var bool |
| 31 |
*/ |
| 32 |
private $isBase64Encoded; |
| 33 |
|
| 34 |
public function __construct(string $data, bool $isBase64Encoded) |
| 35 |
{ |
| 36 |
$this->data = $data; |
| 37 |
$this->isBase64Encoded = $isBase64Encoded; |
| 38 |
} |
| 39 |
|
| 40 |
public function getMetadataStatement(): MetadataStatement |
| 41 |
{ |
| 42 |
if (null === $this->statement) { |
| 43 |
$json = $this->data; |
| 44 |
if ($this->isBase64Encoded) { |
| 45 |
$json = base64_decode($this->data, true); |
| 46 |
} |
| 47 |
$statement = json_decode($json, true); |
| 48 |
$this->statement = MetadataStatement::createFromArray($statement); |
| 49 |
} |
| 50 |
|
| 51 |
return $this->statement; |
| 52 |
} |
| 53 |
} |
| 54 |
|