- md5
- ffbe3ed0c4b7b0eefbee3c18bbbcd98c
- sha1
- 71de6af0ef132d14c50211f1ba31eb1009055fd0
- sha256
- 46f971f437202b5257f6252ebc101ece1dc1c501963eb309958f85d14d410439
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
<?php
declare(strict_types=1);
namespace SpomkyLabs\Pki\X509\AttributeCertificate;
use SpomkyLabs\Pki\X501\ASN1\Attribute;
use SpomkyLabs\Pki\X501\ASN1\AttributeType;
use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue;
use SpomkyLabs\Pki\X501\ASN1\Collection\SequenceOfAttributes;
use SpomkyLabs\Pki\X509\AttributeCertificate\Attribute\AccessIdentityAttributeValue;
use SpomkyLabs\Pki\X509\AttributeCertificate\Attribute\AuthenticationInfoAttributeValue;
use SpomkyLabs\Pki\X509\AttributeCertificate\Attribute\ChargingIdentityAttributeValue;
use SpomkyLabs\Pki\X509\AttributeCertificate\Attribute\GroupAttributeValue;
use SpomkyLabs\Pki\X509\AttributeCertificate\Attribute\RoleAttributeValue;
/**
* Implements *Attributes* ASN.1 type of *AttributeCertificateInfo*.
*
* @see https://tools.ietf.org/html/rfc5755#section-4.1
* @see https://tools.ietf.org/html/rfc5755#section-4.2.7
*/
final class Attributes extends SequenceOfAttributes
{
/**
* Mapping from OID to attribute value class name.
*
* @internal
*
* @var array<string, string>
*/
private const MAP_OID_TO_CLASS = [
AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
GroupAttributeValue::OID => GroupAttributeValue::class,
AttributeType::OID_ROLE => RoleAttributeValue::class,
];
/**
* Initialize from attribute values.
*
* @param AttributeValue ...$values List of attribute values
*/
public static function fromAttributeValues(AttributeValue ...$values): static
{
return static::create(...array_map(static fn (AttributeValue $value) => $value->toAttribute(), $values));
}
/**
* Check whether 'Access Identity' attribute is present.
*/
public function hasAccessIdentity(): bool
{
return $this->has(AccessIdentityAttributeValue::OID);
}
/**
* Get the first 'Access Identity' attribute value.
*/
public function accessIdentity(): AccessIdentityAttributeValue
{
return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
}
/**
* Check whether 'Service Authentication Information' attribute is present.
*/
public function hasAuthenticationInformation(): bool
{
return $this->has(AuthenticationInfoAttributeValue::OID);
}
/**
* Get the first 'Service Authentication Information' attribute value.
*/
public function authenticationInformation(): AuthenticationInfoAttributeValue
{
return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
}
/**
* Check whether 'Charging Identity' attribute is present.
*/
public function hasChargingIdentity(): bool
{
return $this->has(ChargingIdentityAttributeValue::OID);
}
/**
* Get the first 'Charging Identity' attribute value.
*/
public function chargingIdentity(): ChargingIdentityAttributeValue
{
return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
}
/**
* Check whether 'Group' attribute is present.
*/
public function hasGroup(): bool
{
return $this->has(GroupAttributeValue::OID);
}
/**
* Get the first 'Group' attribute value.
*/
public function group(): GroupAttributeValue
{
return $this->firstOf(GroupAttributeValue::OID)->first();
}
/**
* Check whether 'Role' attribute is present.
*/
public function hasRole(): bool
{
return $this->has(AttributeType::OID_ROLE);
}
/**
* Get the first 'Role' attribute value.
*/
public function role(): RoleAttributeValue
{
return $this->firstOf(AttributeType::OID_ROLE)->first();
}
/**
* Get all 'Role' attribute values.
*
* @return RoleAttributeValue[]
*/
public function roles(): array
{
return array_merge(
[],
...array_map(static fn (Attribute $attr) => $attr->values(), $this->allOf(AttributeType::OID_ROLE))
);
}
protected static function _castAttributeValues(Attribute $attribute): Attribute
{
$oid = $attribute->oid();
if (isset(self::MAP_OID_TO_CLASS[$oid])) {
return $attribute->castValues(self::MAP_OID_TO_CLASS[$oid]);
}
return $attribute;
}
}
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.