<?php

declare(strict_types=1);

namespace Logliy\SpomkyLabs\Pki\ASN1\Type\Primitive;

use Logliy\SpomkyLabs\Pki\ASN1\Type\PrimitiveString;
use Logliy\SpomkyLabs\Pki\ASN1\Type\UniversalClass;

/**
 * Implements *VisibleString* type.
 */
final class VisibleString extends PrimitiveString
{
    use UniversalClass;

    private function __construct(string $string)
    {
        parent::__construct(self::TYPE_VISIBLE_STRING, $string);
    }

    public static function create(string $string): self
    {
        return new self($string);
    }

    protected function validateString(string $string): bool
    {
        return preg_match('/[^\x20-\x7e]/', $string) !== 1;
    }
}
