<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Cipher; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; use UnexpectedValueException; use function mb_strlen; abstract class CipherAlgorithmIdentifier extends SpecificAlgorithmIdentifier { protected function __construct( string $oid, protected string $initializationVector ) { $this->_checkIVSize($initializationVector); parent::__construct($oid); } abstract public function keySize(): int; abstract public function ivSize(): int; public function initializationVector(): string { return $this->initializationVector; } public function withInitializationVector(string $iv): self { $this->_checkIVSize($iv); $obj = clone $this; $obj->initializationVector = $iv; return $obj; } protected function _checkIVSize(string $iv): void { if (mb_strlen($iv, '8bit') !== $this->ivSize()) { throw new UnexpectedValueException('Invalid IV size.'); } } } 