1 | <?php |
||
26 | final class JWSLoader |
||
27 | { |
||
28 | /** |
||
29 | * @var AlgorithmManager |
||
30 | */ |
||
31 | private $signatureAlgorithmManager; |
||
32 | |||
33 | /** |
||
34 | * @var HeaderCheckerManager |
||
35 | */ |
||
36 | private $headerCheckerManager; |
||
37 | |||
38 | /** |
||
39 | * JWSLoader constructor. |
||
40 | * |
||
41 | * @param AlgorithmManager $signatureAlgorithmManager |
||
42 | * @param HeaderCheckerManager $headerCheckerManager |
||
43 | */ |
||
44 | public function __construct(AlgorithmManager $signatureAlgorithmManager, HeaderCheckerManager $headerCheckerManager) |
||
49 | |||
50 | /** |
||
51 | * @param string $input |
||
52 | * |
||
53 | * @return JWS |
||
54 | */ |
||
55 | public function load(string $input): JWS |
||
59 | |||
60 | /** |
||
61 | * @return string[] |
||
62 | */ |
||
63 | public function getSupportedSignatureAlgorithms(): array |
||
67 | |||
68 | /** |
||
69 | * @param JWS $jws |
||
70 | * @param JWK $jwk |
||
71 | * @param null|string $detachedPayload |
||
72 | * |
||
73 | * @return null|int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
74 | */ |
||
75 | public function verifyWithKey(JWS $jws, JWK $jwk, ?string $detachedPayload = null): ?int |
||
81 | |||
82 | /** |
||
83 | * Verify the signature of the input. |
||
84 | * The input must be a valid JWS. This method is usually called after the "load" method. |
||
85 | * |
||
86 | * @param JWS $jws A JWS object |
||
87 | * @param JWKSet $jwkset The signature will be verified using keys in the key set |
||
88 | * @param null|string $detachedPayload If not null, the value must be the detached payload encoded in Base64 URL safe. If the input contains a payload, throws an exception. |
||
89 | * |
||
90 | * @return null|int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
91 | */ |
||
92 | public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): ?int |
||
102 | |||
103 | /** |
||
104 | * @param JWS $jws |
||
105 | * @param JWKSet $jwkset |
||
106 | * @param Signature $signature |
||
107 | * @param null|string $detachedPayload |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | private function verifySignature(JWS $jws, JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null): bool |
||
131 | |||
132 | /** |
||
133 | * @param JWS $jws |
||
134 | * @param Signature $signature |
||
135 | * @param string|null $detachedPayload |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | private function getInputToVerify(JWS $jws, Signature $signature, ?string $detachedPayload): string |
||
156 | |||
157 | /** |
||
158 | * @param JWS $jws |
||
159 | * @param JWKSet $jwkset |
||
160 | * @param string|null $detachedPayload |
||
161 | * |
||
162 | * @return null|int |
||
163 | */ |
||
164 | private function verifySignatures(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): ?int |
||
181 | |||
182 | /** |
||
183 | * @param JWS $jws |
||
184 | */ |
||
185 | private function checkSignatures(JWS $jws) |
||
191 | |||
192 | /** |
||
193 | * @param JWKSet $jwkset |
||
194 | */ |
||
195 | private function checkJWKSet(JWKSet $jwkset) |
||
201 | |||
202 | /** |
||
203 | * @param JWS $jws |
||
204 | * @param null|string $detachedPayload |
||
205 | */ |
||
206 | private function checkPayload(JWS $jws, ?string $detachedPayload = null) |
||
215 | |||
216 | /** |
||
217 | * @param Signature $signature |
||
218 | * |
||
219 | * @return SignatureAlgorithmInterface |
||
220 | */ |
||
221 | private function getAlgorithm(Signature $signature): SignatureAlgorithmInterface |
||
235 | } |
||
236 |