1 | <?php |
||
18 | class JWS |
||
19 | { |
||
20 | /** |
||
21 | * Protected header. |
||
22 | * |
||
23 | * @var Header $_protectedHeader |
||
24 | */ |
||
25 | protected $_protectedHeader; |
||
26 | |||
27 | /** |
||
28 | * Payload. |
||
29 | * |
||
30 | * @var string $_payload |
||
31 | */ |
||
32 | protected $_payload; |
||
33 | |||
34 | /** |
||
35 | * Input value for the signature computation. |
||
36 | * |
||
37 | * @var string $_signatureInput |
||
38 | */ |
||
39 | protected $_signatureInput; |
||
40 | |||
41 | /** |
||
42 | * Signature. |
||
43 | * |
||
44 | * @var string $_signature |
||
45 | */ |
||
46 | protected $_signature; |
||
47 | |||
48 | /** |
||
49 | * Constructor |
||
50 | * |
||
51 | * @param Header $protected_header JWS Protected Header |
||
52 | * @param string $payload JWS Payload |
||
53 | * @param string $signature_input Input value for the signature computation |
||
54 | * @param string $signature JWS Signature |
||
55 | */ |
||
56 | 23 | protected function __construct(Header $protected_header, $payload, |
|
63 | |||
64 | /** |
||
65 | * Initialize from a compact serialization. |
||
66 | * |
||
67 | * @param string $data |
||
68 | * @return self |
||
69 | */ |
||
70 | 6 | public static function fromCompact($data) { |
|
73 | |||
74 | /** |
||
75 | * Initialize from the parts of a compact serialization. |
||
76 | * |
||
77 | * @param array $parts |
||
78 | * @throws \UnexpectedValueException |
||
79 | * @return self |
||
80 | */ |
||
81 | 11 | public static function fromParts(array $parts) { |
|
93 | |||
94 | /** |
||
95 | * Initialize by signing the payload with given algorithm. |
||
96 | * |
||
97 | * @param string $payload JWS Payload |
||
98 | * @param SignatureAlgorithm $algo Signature algorithm |
||
99 | * @param Header|null $header Desired header. Algorithm specific |
||
100 | * parameters are added automatically. |
||
101 | * @throws \RuntimeException If signature computation fails |
||
102 | * @return self |
||
103 | */ |
||
104 | 14 | public static function sign($payload, SignatureAlgorithm $algo, |
|
124 | |||
125 | /** |
||
126 | * Get JOSE header. |
||
127 | * |
||
128 | * @return JOSE |
||
129 | */ |
||
130 | 13 | public function header() { |
|
133 | |||
134 | /** |
||
135 | * Get the signature algorithm name. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | 11 | public function algorithmName() { |
|
144 | |||
145 | /** |
||
146 | * Get the payload. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 4 | public function payload() { |
|
153 | |||
154 | /** |
||
155 | * Get the signature. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 5 | public function signature() { |
|
162 | |||
163 | /** |
||
164 | * Get the payload encoded for serialization. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | 12 | protected function _encodedPayload() { |
|
175 | |||
176 | /** |
||
177 | * Validate signature. |
||
178 | * |
||
179 | * @param SignatureAlgorithm $algo |
||
180 | * @throws \UnexpectedValueException If using different signature algorithm |
||
181 | * then specified by the header |
||
182 | * @throws \RuntimeException If signature computation fails |
||
183 | * @return bool True if signature is valid |
||
184 | */ |
||
185 | 10 | public function validate(SignatureAlgorithm $algo) { |
|
192 | |||
193 | /** |
||
194 | * Validate signature using given JWK. |
||
195 | * |
||
196 | * Signature algorithm is determined from the header. |
||
197 | * |
||
198 | * @param JWK $jwk JSON Web Key |
||
199 | * @return bool True if signature is valid |
||
200 | */ |
||
201 | 1 | public function validateWithJWK(JWK $jwk) { |
|
205 | |||
206 | /** |
||
207 | * Convert to compact serialization. |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | 12 | public function toCompact() { |
|
216 | |||
217 | /** |
||
218 | * Convert to compact serialization with payload detached. |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | 2 | public function toCompactDetached() { |
|
226 | |||
227 | /** |
||
228 | * Generate input for the signature computation. |
||
229 | * |
||
230 | * @param string $payload Payload |
||
231 | * @param Header $header Protected header |
||
232 | * @return string |
||
233 | */ |
||
234 | 14 | protected static function _generateSignatureInput($payload, Header $header) { |
|
240 | |||
241 | /** |
||
242 | * Convert JWS to string. |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | 1 | public function __toString() { |
|
249 | } |
||
250 |