1 | <?php |
||
27 | final class JWSVerifier |
||
28 | { |
||
29 | /** |
||
30 | * @var AlgorithmManager |
||
31 | */ |
||
32 | private $signatureAlgorithmManager; |
||
33 | |||
34 | /** |
||
35 | * @var HeaderCheckerManager |
||
36 | */ |
||
37 | private $headerCheckerManager; |
||
38 | |||
39 | /** |
||
40 | * JWSVerifier constructor. |
||
41 | * |
||
42 | * @param AlgorithmManager $signatureAlgorithmManager |
||
43 | * @param HeaderCheckerManager $headerCheckerManager |
||
44 | */ |
||
45 | public function __construct(AlgorithmManager $signatureAlgorithmManager, HeaderCheckerManager $headerCheckerManager) |
||
50 | |||
51 | /** |
||
52 | * @return AlgorithmManager |
||
53 | */ |
||
54 | public function getSignatureAlgorithmManager(): AlgorithmManager |
||
58 | |||
59 | /** |
||
60 | * @param JWS $jws |
||
61 | * @param JWK $jwk |
||
62 | * @param null|string $detachedPayload |
||
63 | * |
||
64 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
65 | */ |
||
66 | public function verifyWithKey(JWS $jws, JWK $jwk, ?string $detachedPayload = null): int |
||
72 | |||
73 | /** |
||
74 | * Verify the signature of the input. |
||
75 | * The input must be a valid JWS. This method is usually called after the "load" method. |
||
76 | * |
||
77 | * @param JWS $jws A JWS object |
||
78 | * @param JWKSet $jwkset The signature will be verified using keys in the key set |
||
79 | * @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. |
||
80 | * |
||
81 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
82 | */ |
||
83 | public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): int |
||
105 | |||
106 | /** |
||
107 | * @param JWS $jws |
||
108 | * @param JWKSet $jwkset |
||
109 | * @param Signature $signature |
||
110 | * @param null|string $detachedPayload |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | private function verifySignature(JWS $jws, JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null): bool |
||
134 | |||
135 | /** |
||
136 | * @param JWS $jws |
||
137 | * @param Signature $signature |
||
138 | * @param string|null $detachedPayload |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | private function getInputToVerify(JWS $jws, Signature $signature, ?string $detachedPayload): string |
||
159 | |||
160 | /** |
||
161 | * @param JWS $jws |
||
162 | */ |
||
163 | private function checkSignatures(JWS $jws) |
||
169 | |||
170 | /** |
||
171 | * @param JWKSet $jwkset |
||
172 | */ |
||
173 | private function checkJWKSet(JWKSet $jwkset) |
||
179 | |||
180 | /** |
||
181 | * @param JWS $jws |
||
182 | * @param null|string $detachedPayload |
||
183 | */ |
||
184 | private function checkPayload(JWS $jws, ?string $detachedPayload = null) |
||
193 | |||
194 | /** |
||
195 | * @param Signature $signature |
||
196 | * |
||
197 | * @return SignatureAlgorithmInterface |
||
198 | */ |
||
199 | private function getAlgorithm(Signature $signature): SignatureAlgorithmInterface |
||
213 | } |
||
214 |