1 | <?php |
||
28 | final class JWSLoader |
||
29 | { |
||
30 | /** |
||
31 | * @var AlgorithmManager |
||
32 | */ |
||
33 | private $signatureAlgorithmManager; |
||
34 | |||
35 | /** |
||
36 | * @var HeaderCheckerManager |
||
37 | */ |
||
38 | private $headerCheckerManager; |
||
39 | |||
40 | /** |
||
41 | * @var JWSSerializerManager |
||
42 | */ |
||
43 | private $serializerManager; |
||
44 | |||
45 | /** |
||
46 | * JWSLoader constructor. |
||
47 | * |
||
48 | * @param AlgorithmManager $signatureAlgorithmManager |
||
49 | * @param HeaderCheckerManager $headerCheckerManager |
||
50 | * @param JWSSerializerManager $serializerManager |
||
51 | */ |
||
52 | public function __construct(AlgorithmManager $signatureAlgorithmManager, HeaderCheckerManager $headerCheckerManager, JWSSerializerManager $serializerManager) |
||
58 | |||
59 | /** |
||
60 | * @param string $input |
||
61 | * @param string|null $serializer |
||
62 | * |
||
63 | * @return JWS |
||
64 | */ |
||
65 | public function load(string $input, ?string &$serializer = null): JWS |
||
69 | |||
70 | /** |
||
71 | * @return AlgorithmManager |
||
72 | */ |
||
73 | public function getSignatureAlgorithmManager(): AlgorithmManager |
||
77 | |||
78 | /** |
||
79 | * @param JWS $jws |
||
80 | * @param JWK $jwk |
||
81 | * @param null|string $detachedPayload |
||
82 | * |
||
83 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
84 | */ |
||
85 | public function verifyWithKey(JWS $jws, JWK $jwk, ?string $detachedPayload = null): int |
||
91 | |||
92 | /** |
||
93 | * Verify the signature of the input. |
||
94 | * The input must be a valid JWS. This method is usually called after the "load" method. |
||
95 | * |
||
96 | * @param JWS $jws A JWS object |
||
97 | * @param JWKSet $jwkset The signature will be verified using keys in the key set |
||
98 | * @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. |
||
99 | * |
||
100 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
101 | */ |
||
102 | public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): int |
||
112 | |||
113 | /** |
||
114 | * @param JWS $jws |
||
115 | * @param JWKSet $jwkset |
||
116 | * @param Signature $signature |
||
117 | * @param null|string $detachedPayload |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | private function verifySignature(JWS $jws, JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null): bool |
||
141 | |||
142 | /** |
||
143 | * @param JWS $jws |
||
144 | * @param Signature $signature |
||
145 | * @param string|null $detachedPayload |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | private function getInputToVerify(JWS $jws, Signature $signature, ?string $detachedPayload): string |
||
166 | |||
167 | /** |
||
168 | * @param JWS $jws |
||
169 | * @param JWKSet $jwkset |
||
170 | * @param string|null $detachedPayload |
||
171 | * |
||
172 | * @return null|int |
||
173 | */ |
||
174 | private function verifySignatures(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): ?int |
||
191 | |||
192 | /** |
||
193 | * @param JWS $jws |
||
194 | */ |
||
195 | private function checkSignatures(JWS $jws) |
||
201 | |||
202 | /** |
||
203 | * @param JWKSet $jwkset |
||
204 | */ |
||
205 | private function checkJWKSet(JWKSet $jwkset) |
||
211 | |||
212 | /** |
||
213 | * @param JWS $jws |
||
214 | * @param null|string $detachedPayload |
||
215 | */ |
||
216 | private function checkPayload(JWS $jws, ?string $detachedPayload = null) |
||
225 | |||
226 | /** |
||
227 | * @param Signature $signature |
||
228 | * |
||
229 | * @return SignatureAlgorithmInterface |
||
230 | */ |
||
231 | private function getAlgorithm(Signature $signature): SignatureAlgorithmInterface |
||
245 | } |
||
246 |