| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cose\Signature; |
| 6 | |
| 7 | use CBOR\ByteStringObject; |
| 8 | use CBOR\ListObject; |
| 9 | use CBOR\TextStringObject; |
| 10 | use Stringable; |
| 11 | |
| 12 | final class Signature1 implements Stringable |
| 13 | { |
| 14 | public function __construct( |
| 15 | private readonly ByteStringObject $protectedHeader, |
| 16 | private readonly ByteStringObject $payload |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | public function __toString(): string |
| 21 | { |
| 22 | $structure = new ListObject(); |
| 23 | $structure->add(new TextStringObject('Signature1')); |
| 24 | $structure->add($this->protectedHeader); |
| 25 | $structure->add(new ByteStringObject('')); |
| 26 | $structure->add($this->payload); |
| 27 | |
| 28 | return (string) $structure; |
| 29 | } |
| 30 | |
| 31 | public static function create(ByteStringObject $protectedHeader, ByteStringObject $payload): self |
| 32 | { |
| 33 | return new self($protectedHeader, $payload); |
| 34 | } |
| 35 | |
| 36 | public function getProtectedHeader(): ByteStringObject |
| 37 | { |
| 38 | return $this->protectedHeader; |
| 39 | } |
| 40 | |
| 41 | public function getPayload(): ByteStringObject |
| 42 | { |
| 43 | return $this->payload; |
| 44 | } |
| 45 | } |