<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\CryptoTypes\Signature; use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString; use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer; use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; final class ECSignature extends Signature { private function __construct( private readonly string $r, private readonly string $s ) { } public static function create(string $r, string $s): self { return new self($r, $s); } public static function fromASN1(Sequence $seq): self { $r = $seq->at(0) ->asInteger() ->number(); $s = $seq->at(1) ->asInteger() ->number(); return self::create($r, $s); } public static function fromDER(string $data): self { return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); } public function r(): string { return $this->r; } public function s(): string { return $this->s; } public function toASN1(): Sequence { return Sequence::create(Integer::create($this->r), Integer::create($this->s)); } public function toDER(): string { return $this->toASN1() ->toDER(); } public function bitString(): BitString { return BitString::create($this->toDER()); } } 