toDER()); } /** * Get the public key as a PublicKeyInfo type. */ public function publicKeyInfo(): PublicKeyInfo { return PublicKeyInfo::fromPublicKey($this); } /** * Initialize public key from PEM. * * @return PublicKey */ public static function fromPEM(PEM $pem) { return match ($pem->type()) { PEM::TYPE_RSA_PUBLIC_KEY => RSAPublicKey::fromDER($pem->data()), PEM::TYPE_PUBLIC_KEY => PublicKeyInfo::fromPEM($pem)->publicKey(), default => throw new UnexpectedValueException('PEM type ' . $pem->type() . ' is not a valid public key.'), }; } }