1 | <?php |
||
22 | final class JWS implements JWTInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | private $isPayloadDetached = false; |
||
28 | |||
29 | /** |
||
30 | * @var string|null |
||
31 | */ |
||
32 | private $encodedPayload = null; |
||
33 | |||
34 | /** |
||
35 | * @var Signature[] |
||
36 | */ |
||
37 | private $signatures = []; |
||
38 | |||
39 | /** |
||
40 | * @var string|null |
||
41 | */ |
||
42 | private $payload = null; |
||
43 | |||
44 | /** |
||
45 | * JWS constructor. |
||
46 | * |
||
47 | * @param string|null $payload |
||
48 | * @param string|null $encodedPayload |
||
49 | * @param bool $isPayloadDetached |
||
50 | */ |
||
51 | private function __construct(?string $payload, ?string $encodedPayload = null, bool $isPayloadDetached = false) |
||
52 | { |
||
53 | $this->payload = $payload; |
||
54 | $this->encodedPayload = $encodedPayload; |
||
55 | $this->isPayloadDetached = $isPayloadDetached; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string|null $payload |
||
60 | * @param string|null $encodedPayload |
||
61 | * @param bool $isPayloadDetached |
||
62 | * |
||
63 | * @return JWS |
||
64 | */ |
||
65 | public static function create(?string $payload, ?string $encodedPayload = null, bool $isPayloadDetached = false): JWS |
||
66 | { |
||
67 | return new self($payload, $encodedPayload, $isPayloadDetached); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function getPayload(): ?string |
||
77 | |||
78 | /** |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function isPayloadDetached(): bool |
||
85 | |||
86 | /** |
||
87 | * @return string|null |
||
88 | */ |
||
89 | public function getEncodedPayload(): ?string |
||
97 | |||
98 | /** |
||
99 | * Returns the signature associated with the JWS. |
||
100 | * |
||
101 | * @return Signature[] |
||
102 | */ |
||
103 | public function getSignatures(): array |
||
107 | |||
108 | /** |
||
109 | * @param int $id |
||
110 | * |
||
111 | * @return Signature |
||
112 | */ |
||
113 | public function getSignature(int $id): Signature |
||
121 | |||
122 | /** |
||
123 | * @param string $signature |
||
124 | * @param array $protectedHeaders |
||
125 | * @param string|null $encodedProtectedHeaders |
||
126 | * @param array $headers |
||
127 | * |
||
128 | * @return JWS |
||
129 | */ |
||
130 | public function addSignature(string $signature, array $protectedHeaders, ?string $encodedProtectedHeaders, array $headers = []): JWS |
||
137 | |||
138 | /** |
||
139 | * Returns the number of signature associated with the JWS. |
||
140 | * |
||
141 | * |
||
142 | * @return int |
||
143 | */ |
||
144 | public function countSignatures(): int |
||
148 | |||
149 | /** |
||
150 | * @param int $id |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | public function toCompactJSON(int $id): string |
||
171 | |||
172 | /** |
||
173 | * @param int $id |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | public function toFlattenedJSON(int $id): string |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | public function toJSON(): string |
||
232 | |||
233 | /** |
||
234 | * @param Signature $signature |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | private function isPayloadEncoded(Signature $signature): bool |
||
242 | |||
243 | private function checkPayloadEncoding() |
||
257 | } |
||
258 |