<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric; use SpomkyLabs\Pki\ASN1\Element; use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier; use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AsymmetricCryptoAlgorithmIdentifier; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; use UnexpectedValueException; final class ECPublicKeyAlgorithmIdentifier extends SpecificAlgorithmIdentifier implements AsymmetricCryptoAlgorithmIdentifier { final public const CURVE_PRIME192V1 = '1.2.840.10045.3.1.1'; final public const CURVE_PRIME192V2 = '1.2.840.10045.3.1.2'; final public const CURVE_PRIME192V3 = '1.2.840.10045.3.1.3'; final public const CURVE_PRIME239V1 = '1.2.840.10045.3.1.4'; final public const CURVE_PRIME239V2 = '1.2.840.10045.3.1.5'; final public const CURVE_PRIME239V3 = '1.2.840.10045.3.1.6'; final public const CURVE_PRIME256V1 = '1.2.840.10045.3.1.7'; final public const CURVE_SECP112R1 = '1.3.132.0.6'; final public const CURVE_SECP112R2 = '1.3.132.0.7'; final public const CURVE_SECP128R1 = '1.3.132.0.28'; final public const CURVE_SECP128R2 = '1.3.132.0.29'; final public const CURVE_SECP160K1 = '1.3.132.0.9'; final public const CURVE_SECP160R1 = '1.3.132.0.8'; final public const CURVE_SECP160R2 = '1.3.132.0.30'; final public const CURVE_SECP192K1 = '1.3.132.0.31'; final public const CURVE_SECP224K1 = '1.3.132.0.32'; final public const CURVE_SECP224R1 = '1.3.132.0.33'; final public const CURVE_SECP256K1 = '1.3.132.0.10'; final public const CURVE_SECP384R1 = '1.3.132.0.34'; final public const CURVE_SECP521R1 = '1.3.132.0.35'; final public const MAP_CURVE_TO_SIZE = [ self::CURVE_PRIME192V1 => 192, self::CURVE_PRIME192V2 => 192, self::CURVE_PRIME192V3 => 192, self::CURVE_PRIME239V1 => 239, self::CURVE_PRIME239V2 => 239, self::CURVE_PRIME239V3 => 239, self::CURVE_PRIME256V1 => 256, self::CURVE_SECP112R1 => 112, self::CURVE_SECP112R2 => 112, self::CURVE_SECP128R1 => 128, self::CURVE_SECP128R2 => 128, self::CURVE_SECP160K1 => 160, self::CURVE_SECP160R1 => 160, self::CURVE_SECP160R2 => 160, self::CURVE_SECP192K1 => 192, self::CURVE_SECP224K1 => 224, self::CURVE_SECP224R1 => 224, self::CURVE_SECP256K1 => 256, self::CURVE_SECP384R1 => 384, self::CURVE_SECP521R1 => 521, ]; private function __construct( private readonly string $namedCurve ) { parent::__construct(self::OID_EC_PUBLIC_KEY); } public static function create(string $namedCurve): self { return new self($namedCurve); } public function name(): string { return 'ecPublicKey'; } public static function fromASN1Params(?UnspecifiedType $params = null): SpecificAlgorithmIdentifier { if (! isset($params)) { throw new UnexpectedValueException('No parameters.'); } $named_curve = $params->asObjectIdentifier() ->oid(); return self::create($named_curve); } public function namedCurve(): string { return $this->namedCurve; } protected function paramsASN1(): Element { return ObjectIdentifier::create($this->namedCurve); } } 