<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\ASN1\Type; use InvalidArgumentException; use SpomkyLabs\Pki\ASN1\Element; use Stringable; use function sprintf; abstract class BaseString extends Element implements StringType, Stringable { private readonly string $string; protected function __construct(int $typeTag, string $string) { parent::__construct($typeTag); if (! $this->validateString($string)) { throw new InvalidArgumentException(sprintf('Not a valid %s string.', self::tagToName($this->typeTag))); } $this->string = $string; } public function __toString(): string { return $this->string(); } public function string(): string { return $this->string; } protected function encodedAsDER(): string { return $this->string; } protected function validateString(string $string): bool { return true; } } 