/** * Initialize signature algorithm from a JWK and a header. * * @param JWK $jwk JSON Web Key * @param Header $header Header * @return SignatureAlgorithm */ public static function fromJWK(JWK $jwk, Header $header) { $factory = new SignatureAlgorithmFactory($header); return $factory->algoByKey($jwk); }
/** * Validate the signature using a key from the given JWK set. * * Correct key shall be sought by the key ID indicated by the header. * * @param JWKSet $set Set of JSON Web Keys * @throws \RuntimeException If algorithm initialization fails * @return bool True if signature is valid */ public function validateWithJWKSet(JWKSet $set) { if (!count($set)) { throw new \RuntimeException("No keys."); } $factory = new SignatureAlgorithmFactory($this->header()); $algo = $factory->algoByKeys($set); return $this->validate($algo); }