| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\AttributeCertificate\Attribute; |
| 6 |
|
| 7 |
use LogicException; |
| 8 |
use SpomkyLabs\Pki\ASN1\Element; |
| 9 |
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; |
| 10 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString; |
| 11 |
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 12 |
use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue; |
| 13 |
use SpomkyLabs\Pki\X501\MatchingRule\BinaryMatch; |
| 14 |
use SpomkyLabs\Pki\X501\MatchingRule\MatchingRule; |
| 15 |
use SpomkyLabs\Pki\X509\GeneralName\GeneralName; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
abstract class SvceAuthInfo extends AttributeValue |
| 23 |
{ |
| 24 |
protected function __construct( |
| 25 |
string $oid, |
| 26 |
private readonly GeneralName $service, |
| 27 |
private readonly GeneralName $ident, |
| 28 |
private readonly ?string $authInfo = null |
| 29 |
) { |
| 30 |
parent::__construct($oid); |
| 31 |
} |
| 32 |
|
| 33 |
abstract public static function fromASN1(UnspecifiedType $el): static; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function service(): GeneralName |
| 39 |
{ |
| 40 |
return $this->service; |
| 41 |
} |
| 42 |
|
| 43 |
public function ident(): GeneralName |
| 44 |
{ |
| 45 |
return $this->ident; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function hasAuthInfo(): bool |
| 52 |
{ |
| 53 |
return isset($this->authInfo); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public function authInfo(): string |
| 60 |
{ |
| 61 |
if (! $this->hasAuthInfo()) { |
| 62 |
throw new LogicException('authInfo not set.'); |
| 63 |
} |
| 64 |
return $this->authInfo; |
| 65 |
} |
| 66 |
|
| 67 |
public function toASN1(): Element |
| 68 |
{ |
| 69 |
$elements = [$this->service->toASN1(), $this->ident->toASN1()]; |
| 70 |
if (isset($this->authInfo)) { |
| 71 |
$elements[] = OctetString::create($this->authInfo); |
| 72 |
} |
| 73 |
return Sequence::create(...$elements); |
| 74 |
} |
| 75 |
|
| 76 |
public function stringValue(): string |
| 77 |
{ |
| 78 |
return '#' . bin2hex($this->toASN1()->toDER()); |
| 79 |
} |
| 80 |
|
| 81 |
public function equalityMatchingRule(): MatchingRule |
| 82 |
{ |
| 83 |
return new BinaryMatch(); |
| 84 |
} |
| 85 |
|
| 86 |
public function rfc2253String(): string |
| 87 |
{ |
| 88 |
return $this->stringValue(); |
| 89 |
} |
| 90 |
|
| 91 |
protected function _transcodedString(): string |
| 92 |
{ |
| 93 |
return $this->stringValue(); |
| 94 |
} |
| 95 |
} |