1 | <?php |
||
19 | class JWE implements JWT |
||
20 | { |
||
21 | /** |
||
22 | * @var Recipient[] |
||
23 | */ |
||
24 | private $recipients = []; |
||
25 | |||
26 | /** |
||
27 | * @var null|string |
||
28 | */ |
||
29 | private $ciphertext; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $iv; |
||
35 | |||
36 | /** |
||
37 | * @var null|string |
||
38 | */ |
||
39 | private $aad; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $tag; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | private $sharedHeader = []; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | private $sharedProtectedHeader = []; |
||
55 | |||
56 | /** |
||
57 | * @var null|string |
||
58 | */ |
||
59 | private $encodedSharedProtectedHeader; |
||
60 | |||
61 | /** |
||
62 | * @var null|string |
||
63 | */ |
||
64 | private $payload; |
||
65 | |||
66 | public function __construct(string $ciphertext, string $iv, string $tag, ?string $aad = null, array $sharedHeader = [], array $sharedProtectedHeader = [], ?string $encodedSharedProtectedHeader = null, array $recipients = []) |
||
77 | |||
78 | public function getPayload(): ?string |
||
82 | |||
83 | /** |
||
84 | * Set the payload. |
||
85 | * This method is immutable and a new object will be returned. |
||
86 | * |
||
87 | * @return JWE |
||
88 | */ |
||
89 | public function withPayload(string $payload): self |
||
96 | |||
97 | /** |
||
98 | * Returns the number of recipients associated with the JWS. |
||
99 | */ |
||
100 | public function countRecipients(): int |
||
104 | |||
105 | /** |
||
106 | * Returns true is the JWE has already been encrypted. |
||
107 | */ |
||
108 | public function isEncrypted(): bool |
||
112 | |||
113 | /** |
||
114 | * Returns the recipients associated with the JWS. |
||
115 | * |
||
116 | * @return Recipient[] |
||
117 | */ |
||
118 | public function getRecipients(): array |
||
122 | |||
123 | /** |
||
124 | * Returns the recipient object at the given index. |
||
125 | * |
||
126 | * @throws InvalidArgumentException if the recipient ID does not exist |
||
127 | */ |
||
128 | public function getRecipient(int $id): Recipient |
||
136 | |||
137 | /** |
||
138 | * Returns the ciphertext. This method will return null is the JWE has not yet been encrypted. |
||
139 | * |
||
140 | * @return null|string The cyphertext |
||
141 | */ |
||
142 | public function getCiphertext(): ?string |
||
146 | |||
147 | /** |
||
148 | * Returns the Additional Authentication Data if available. |
||
149 | */ |
||
150 | public function getAAD(): ?string |
||
154 | |||
155 | /** |
||
156 | * Returns the Initialization Vector if available. |
||
157 | */ |
||
158 | public function getIV(): ?string |
||
162 | |||
163 | /** |
||
164 | * Returns the tag if available. |
||
165 | */ |
||
166 | public function getTag(): ?string |
||
170 | |||
171 | /** |
||
172 | * Returns the encoded shared protected header. |
||
173 | */ |
||
174 | public function getEncodedSharedProtectedHeader(): string |
||
178 | |||
179 | /** |
||
180 | * Returns the shared protected header. |
||
181 | */ |
||
182 | public function getSharedProtectedHeader(): array |
||
186 | |||
187 | /** |
||
188 | * Returns the shared protected header parameter identified by the given key. |
||
189 | * Throws an exception is the the parameter is not available. |
||
190 | * |
||
191 | * @param string $key The key |
||
192 | * |
||
193 | * @throws InvalidArgumentException if the shared protected header parameter does not exist |
||
194 | * |
||
195 | * @return null|mixed |
||
196 | */ |
||
197 | public function getSharedProtectedHeaderParameter(string $key) |
||
205 | |||
206 | /** |
||
207 | * Returns true if the shared protected header has the parameter identified by the given key. |
||
208 | * |
||
209 | * @param string $key The key |
||
210 | */ |
||
211 | public function hasSharedProtectedHeaderParameter(string $key): bool |
||
215 | |||
216 | /** |
||
217 | * Returns the shared header. |
||
218 | */ |
||
219 | public function getSharedHeader(): array |
||
223 | |||
224 | /** |
||
225 | * Returns the shared header parameter identified by the given key. |
||
226 | * Throws an exception is the the parameter is not available. |
||
227 | * |
||
228 | * @param string $key The key |
||
229 | * |
||
230 | * @throws InvalidArgumentException if the shared header parameter does not exist |
||
231 | * |
||
232 | * @return null|mixed |
||
233 | */ |
||
234 | public function getSharedHeaderParameter(string $key) |
||
242 | |||
243 | /** |
||
244 | * Returns true if the shared header has the parameter identified by the given key. |
||
245 | * |
||
246 | * @param string $key The key |
||
247 | */ |
||
248 | public function hasSharedHeaderParameter(string $key): bool |
||
252 | |||
253 | /** |
||
254 | * This method splits the JWE into a list of JWEs. |
||
255 | * It is only useful when the JWE contains more than one recipient (JSON General Serialization). |
||
256 | * |
||
257 | * @return JWE[] |
||
258 | */ |
||
259 | public function split(): array |
||
277 | } |
||
278 |