<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\CryptoTypes\Signature; use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric\Ed25519AlgorithmIdentifier; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric\Ed448AlgorithmIdentifier; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Signature\ECSignatureAlgorithmIdentifier; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Signature\RSASignatureAlgorithmIdentifier; abstract class Signature { abstract public function bitString(): BitString; public static function fromSignatureData(string $data, AlgorithmIdentifierType $algo): self { if ($algo instanceof RSASignatureAlgorithmIdentifier) { return RSASignature::fromSignatureString($data); } if ($algo instanceof ECSignatureAlgorithmIdentifier) { return ECSignature::fromDER($data); } if ($algo instanceof Ed25519AlgorithmIdentifier) { return Ed25519Signature::create($data); } if ($algo instanceof Ed448AlgorithmIdentifier) { return Ed448Signature::create($data); } return GenericSignature::create(BitString::create($data), $algo); } } 