1 | <?php |
||
26 | final class JWSVerifier |
||
27 | { |
||
28 | /** |
||
29 | * @var AlgorithmManager |
||
30 | */ |
||
31 | private $signatureAlgorithmManager; |
||
32 | |||
33 | /** |
||
34 | * JWSVerifier constructor. |
||
35 | * |
||
36 | * @param AlgorithmManager $signatureAlgorithmManager |
||
37 | */ |
||
38 | public function __construct(AlgorithmManager $signatureAlgorithmManager) |
||
42 | |||
43 | /** |
||
44 | * @return AlgorithmManager |
||
45 | */ |
||
46 | public function getSignatureAlgorithmManager(): AlgorithmManager |
||
50 | |||
51 | /** |
||
52 | * @param JWS $jws |
||
53 | * @param JWK $jwk |
||
54 | * @param null|string $detachedPayload |
||
55 | * |
||
56 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
57 | */ |
||
58 | public function verifyWithKey(JWS $jws, JWK $jwk, ?string $detachedPayload = null): int |
||
64 | |||
65 | /** |
||
66 | * Verify the signature of the input. |
||
67 | * The input must be a valid JWS. This method is usually called after the "load" method. |
||
68 | * |
||
69 | * @param JWS $jws A JWS object |
||
70 | * @param JWKSet $jwkset The signature will be verified using keys in the key set |
||
71 | * @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. |
||
72 | * |
||
73 | * @return int If the JWS has been verified, an integer that represents the ID of the signature is set |
||
74 | */ |
||
75 | public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, ?string $detachedPayload = null): int |
||
92 | |||
93 | /** |
||
94 | * @param JWS $jws |
||
95 | * @param JWKSet $jwkset |
||
96 | * @param Signature $signature |
||
97 | * @param null|string $detachedPayload |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | private function verifySignature(JWS $jws, JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null): bool |
||
124 | |||
125 | /** |
||
126 | * @param JWS $jws |
||
127 | * @param Signature $signature |
||
128 | * @param string|null $detachedPayload |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | private function getInputToVerify(JWS $jws, Signature $signature, ?string $detachedPayload): string |
||
149 | |||
150 | /** |
||
151 | * @param JWS $jws |
||
152 | */ |
||
153 | private function checkSignatures(JWS $jws) |
||
159 | |||
160 | /** |
||
161 | * @param JWKSet $jwkset |
||
162 | */ |
||
163 | private function checkJWKSet(JWKSet $jwkset) |
||
169 | |||
170 | /** |
||
171 | * @param JWS $jws |
||
172 | * @param null|string $detachedPayload |
||
173 | */ |
||
174 | private function checkPayload(JWS $jws, ?string $detachedPayload = null) |
||
183 | |||
184 | /** |
||
185 | * @param Signature $signature |
||
186 | * |
||
187 | * @return SignatureAlgorithm |
||
188 | */ |
||
189 | private function getAlgorithm(Signature $signature): SignatureAlgorithm |
||
203 | } |
||
204 |