primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Webauthn\TrustPath;
use function array_key_exists;
use function is_array;
use Webauthn\Exception\InvalidTrustPathException;
final class CertificateTrustPath implements TrustPath
{
/**
* @param string[] $certificates
*/
public function __construct(
private readonly array $certificates
) {
}
/**
* @param string[] $certificates
*/
public static function create(array $certificates): self
{
return new self($certificates);
}
/**
* @return string[]
*/
public function getCertificates(): array
{
return $this->certificates;
}
/**
* {@inheritdoc}
*/
public static function createFromArray(array $data): static
{
array_key_exists('x5c', $data) || throw InvalidTrustPathException::create('The trust path type is invalid');
$x5c = $data['x5c'];
is_array($x5c) || throw InvalidTrustPathException::create(
'The trust path type is invalid. The parameter "x5c" shall contain strings.'
);
return new self($x5c);
}
/**
* @return mixed[]
*/
public function jsonSerialize(): array
{
return [
'type' => self::class,
'x5c' => $this->certificates,
];
}
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Webauthn\TrustPath;
use function array_key_exists;
use Webauthn\Exception\InvalidTrustPathException;
/**
* @deprecated since 4.2.0 and will be removed in 5.0.0. The ECDAA Trust Anchor does no longer exist in Webauthn specification.
*/
final class EcdaaKeyIdTrustPath implements TrustPath
{
public function __construct(
private readonly string $ecdaaKeyId
) {
}
public function getEcdaaKeyId(): string
{
return $this->ecdaaKeyId;
}
/**
* @return string[]
*/
public function jsonSerialize(): array
{
return [
'type' => self::class,
'ecdaaKeyId' => $this->ecdaaKeyId,
];
}
/**
* {@inheritdoc}
*/
public static function createFromArray(array $data): static
{
array_key_exists('ecdaaKeyId', $data) || throw InvalidTrustPathException::create(
'The trust path type is invalid'
);
return new self($data['ecdaaKeyId']);
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Webauthn\TrustPath;
final class EmptyTrustPath implements TrustPath
{
public static function create(): self
{
return new self();
}
/**
* @return string[]
*/
public function jsonSerialize(): array
{
return [
'type' => self::class,
];
}
/**
* {@inheritdoc}
*/
public static function createFromArray(array $data): static
{
return new self();
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Webauthn\TrustPath;
use JsonSerializable;
interface TrustPath extends JsonSerializable
{
/**
* @param array<string, mixed> $data
*/
public static function createFromArray(array $data): static;
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Webauthn\TrustPath;
use function array_key_exists;
use function class_implements;
use function in_array;
use Webauthn\Exception\InvalidTrustPathException;
abstract class TrustPathLoader
{
/**
* @param mixed[] $data
*/
public static function loadTrustPath(array $data): TrustPath
{
array_key_exists('type', $data) || throw InvalidTrustPathException::create('The trust path type is missing');
$type = $data['type'];
if (class_exists($type) !== true) {
throw InvalidTrustPathException::create(
sprintf('The trust path type "%s" is not supported', $data['type'])
);
}
$implements = class_implements($type);
if (in_array(TrustPath::class, $implements, true)) {
return $type::createFromArray($data);
}
throw InvalidTrustPathException::create(sprintf('The trust path type "%s" is not supported', $data['type']));
}
}