- md5
- 1006b77868447877a4ad1300c9580ffc
- sha1
- 40a3cee777b68d8b0d561032236b722214348392
- sha256
- ee1b788e44aa6ef1b92a2aa1acebc8d4bd68380e72ca63df6444ea4c102219ed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
<?php
declare(strict_types=1);
namespace SpomkyLabs\Pki\X509\Certificate\Extension;
use LogicException;
use SpomkyLabs\Pki\ASN1\Element;
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType;
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
use SpomkyLabs\Pki\X509\Certificate\Extension\NameConstraints\GeneralSubtrees;
/**
* Implements 'Name Constraints' certificate extension.
*
* @see https://tools.ietf.org/html/rfc5280#section-4.2.1.10
*/
final class NameConstraintsExtension extends Extension
{
private function __construct(
bool $critical,
private readonly ?GeneralSubtrees $permitted,
private readonly ?GeneralSubtrees $excluded
) {
parent::__construct(self::OID_NAME_CONSTRAINTS, $critical);
}
public static function create(
bool $critical,
?GeneralSubtrees $permitted = null,
?GeneralSubtrees $excluded = null
): self {
return new self($critical, $permitted, $excluded);
}
/**
* Whether permitted subtrees are present.
*/
public function hasPermittedSubtrees(): bool
{
return isset($this->permitted);
}
/**
* Get permitted subtrees.
*/
public function permittedSubtrees(): GeneralSubtrees
{
if (! $this->hasPermittedSubtrees()) {
throw new LogicException('No permitted subtrees.');
}
return $this->permitted;
}
/**
* Whether excluded subtrees are present.
*/
public function hasExcludedSubtrees(): bool
{
return isset($this->excluded);
}
/**
* Get excluded subtrees.
*/
public function excludedSubtrees(): GeneralSubtrees
{
if (! $this->hasExcludedSubtrees()) {
throw new LogicException('No excluded subtrees.');
}
return $this->excluded;
}
protected static function fromDER(string $data, bool $critical): static
{
$seq = UnspecifiedType::fromDER($data)->asSequence();
$permitted = null;
$excluded = null;
if ($seq->hasTagged(0)) {
$permitted = GeneralSubtrees::fromASN1(
$seq->getTagged(0)
->asImplicit(Element::TYPE_SEQUENCE)->asSequence()
);
}
if ($seq->hasTagged(1)) {
$excluded = GeneralSubtrees::fromASN1(
$seq->getTagged(1)
->asImplicit(Element::TYPE_SEQUENCE)->asSequence()
);
}
return self::create($critical, $permitted, $excluded);
}
protected function valueASN1(): Element
{
$elements = [];
if (isset($this->permitted)) {
$elements[] = ImplicitlyTaggedType::create(0, $this->permitted->toASN1());
}
if (isset($this->excluded)) {
$elements[] = ImplicitlyTaggedType::create(1, $this->excluded->toASN1());
}
return Sequence::create(...$elements);
}
}
The same content is in 158 releases, Joomla 5.0.0-alpha1 to 6.3.0-alpha1. See them all, or every version of this file.