| 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 Assert\Assertion; |
| 17 |
use Base64Url\Base64Url; |
| 18 |
use JsonSerializable; |
| 19 |
use function Safe\sprintf; |
| 20 |
|
| 21 |
class EcdaaTrustAnchor implements JsonSerializable |
| 22 |
{ |
| 23 |
/** |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
private $X; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
private $Y; |
| 32 |
|
| 33 |
/** |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
private $c; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
private $sx; |
| 42 |
|
| 43 |
/** |
| 44 |
* @var string |
| 45 |
*/ |
| 46 |
private $sy; |
| 47 |
|
| 48 |
/** |
| 49 |
* @var string |
| 50 |
*/ |
| 51 |
private $G1Curve; |
| 52 |
|
| 53 |
public function __construct(string $X, string $Y, string $c, string $sx, string $sy, string $G1Curve) |
| 54 |
{ |
| 55 |
$this->X = $X; |
| 56 |
$this->Y = $Y; |
| 57 |
$this->c = $c; |
| 58 |
$this->sx = $sx; |
| 59 |
$this->sy = $sy; |
| 60 |
$this->G1Curve = $G1Curve; |
| 61 |
} |
| 62 |
|
| 63 |
public function getX(): string |
| 64 |
{ |
| 65 |
return $this->X; |
| 66 |
} |
| 67 |
|
| 68 |
public function getY(): string |
| 69 |
{ |
| 70 |
return $this->Y; |
| 71 |
} |
| 72 |
|
| 73 |
public function getC(): string |
| 74 |
{ |
| 75 |
return $this->c; |
| 76 |
} |
| 77 |
|
| 78 |
public function getSx(): string |
| 79 |
{ |
| 80 |
return $this->sx; |
| 81 |
} |
| 82 |
|
| 83 |
public function getSy(): string |
| 84 |
{ |
| 85 |
return $this->sy; |
| 86 |
} |
| 87 |
|
| 88 |
public function getG1Curve(): string |
| 89 |
{ |
| 90 |
return $this->G1Curve; |
| 91 |
} |
| 92 |
|
| 93 |
public static function createFromArray(array $data): self |
| 94 |
{ |
| 95 |
$data = Utils::filterNullValues($data); |
| 96 |
foreach (['X', 'Y', 'c', 'sx', 'sy', 'G1Curve'] as $key) { |
| 97 |
Assertion::keyExists($data, $key, sprintf('Invalid data. The key "%s" is missing', $key)); |
| 98 |
} |
| 99 |
|
| 100 |
return new self( |
| 101 |
Base64Url::decode($data['X']), |
| 102 |
Base64Url::decode($data['Y']), |
| 103 |
Base64Url::decode($data['c']), |
| 104 |
Base64Url::decode($data['sx']), |
| 105 |
Base64Url::decode($data['sy']), |
| 106 |
$data['G1Curve'] |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
public function jsonSerialize(): array |
| 111 |
{ |
| 112 |
$data = [ |
| 113 |
'X' => Base64Url::encode($this->X), |
| 114 |
'Y' => Base64Url::encode($this->Y), |
| 115 |
'c' => Base64Url::encode($this->c), |
| 116 |
'sx' => Base64Url::encode($this->sx), |
| 117 |
'sy' => Base64Url::encode($this->sy), |
| 118 |
'G1Curve' => $this->G1Curve, |
| 119 |
]; |
| 120 |
|
| 121 |
return Utils::filterNullValues($data); |
| 122 |
} |
| 123 |
} |
| 124 |
|