Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X501/ASN1/AttributeValue/Feature/PrintableStringValue.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X501\ASN1\AttributeValue\Feature;
6
7 use SpomkyLabs\Pki\ASN1\Element;
8 use SpomkyLabs\Pki\ASN1\Type\Primitive\PrintableString;
9 use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue;
10 use SpomkyLabs\Pki\X501\DN\DNParser;
11 use SpomkyLabs\Pki\X501\MatchingRule\CaseIgnoreMatch;
12 use SpomkyLabs\Pki\X501\MatchingRule\MatchingRule;
13
14 /**
15 * Base class for attribute values having *PrintableString* syntax.
16 */
17 abstract class PrintableStringValue extends AttributeValue
18 {
19 /**
20 * @param string $_string String value
21 */
22 protected function __construct(
23 string $oid,
24 protected string $_string
25 ) {
26 parent::__construct($oid);
27 }
28
29 public function toASN1(): Element
30 {
31 return PrintableString::create($this->_string);
32 }
33
34 public function stringValue(): string
35 {
36 return $this->_string;
37 }
38
39 public function equalityMatchingRule(): MatchingRule
40 {
41 // default to caseIgnoreMatch
42 return CaseIgnoreMatch::create(Element::TYPE_PRINTABLE_STRING);
43 }
44
45 public function rfc2253String(): string
46 {
47 return DNParser::escapeString($this->_transcodedString());
48 }
49
50 protected function _transcodedString(): string
51 {
52 // PrintableString maps directly to UTF-8
53 return $this->_string;
54 }
55 }