- md5
- e6c9235bd8e5ead003c550f833003e01
- sha1
- 2b01af7969d7ec92ba2ae15955c0e10ac0092814
- sha256
- bda7872079e3946006f213828aae614000b9c1e393f9a2fc61583281c408dd1e
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
declare(strict_types=1);
namespace SpomkyLabs\Pki\X509\AttributeCertificate\Attribute;
use LogicException;
use SpomkyLabs\Pki\ASN1\Element;
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType;
use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType;
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
use SpomkyLabs\Pki\X501\ASN1\AttributeType;
use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue;
use SpomkyLabs\Pki\X501\MatchingRule\BinaryMatch;
use SpomkyLabs\Pki\X501\MatchingRule\MatchingRule;
use SpomkyLabs\Pki\X509\GeneralName\GeneralName;
use SpomkyLabs\Pki\X509\GeneralName\GeneralNames;
use SpomkyLabs\Pki\X509\GeneralName\UniformResourceIdentifier;
/**
* Implements value for 'Role' attribute.
*
* @see https://tools.ietf.org/html/rfc5755#section-4.4.5
*/
final class RoleAttributeValue extends AttributeValue
{
/**
* @param GeneralName $roleName Role name
* @param null|GeneralNames $roleAuthority Issuing authority
*/
private function __construct(
private readonly GeneralName $roleName,
private readonly ?GeneralNames $roleAuthority
) {
parent::__construct(AttributeType::OID_ROLE);
}
public static function create(GeneralName $roleName, ?GeneralNames $roleAuthority = null): self
{
return new self($roleName, $roleAuthority);
}
/**
* Initialize from a role string.
*
* @param string $role_name Role name in URI format
* @param null|GeneralNames $authority Issuing authority
*/
public static function fromString(string $role_name, ?GeneralNames $authority = null): self
{
return self::create(UniformResourceIdentifier::create($role_name), $authority);
}
/**
* @return self
*/
public static function fromASN1(UnspecifiedType $el): AttributeValue
{
$seq = $el->asSequence();
$authority = null;
if ($seq->hasTagged(0)) {
$authority = GeneralNames::fromASN1(
$seq->getTagged(0)
->asImplicit(Element::TYPE_SEQUENCE)
->asSequence()
);
}
$name = GeneralName::fromASN1($seq->getTagged(1)->asExplicit()->asTagged());
return self::create($name, $authority);
}
/**
* Check whether issuing authority is present.
*/
public function hasRoleAuthority(): bool
{
return isset($this->roleAuthority);
}
/**
* Get issuing authority.
*/
public function roleAuthority(): GeneralNames
{
if (! $this->hasRoleAuthority()) {
throw new LogicException('roleAuthority not set.');
}
return $this->roleAuthority;
}
/**
* Get role name.
*/
public function roleName(): GeneralName
{
return $this->roleName;
}
public function toASN1(): Element
{
$elements = [];
if (isset($this->roleAuthority)) {
$elements[] = ImplicitlyTaggedType::create(0, $this->roleAuthority->toASN1());
}
$elements[] = ExplicitlyTaggedType::create(1, $this->roleName->toASN1());
return Sequence::create(...$elements);
}
public function stringValue(): string
{
return '#' . bin2hex($this->toASN1()->toDER());
}
public function equalityMatchingRule(): MatchingRule
{
return new BinaryMatch();
}
public function rfc2253String(): string
{
return $this->stringValue();
}
protected function _transcodedString(): string
{
return $this->stringValue();
}
}
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.