public static function fromPEM(PEM $pem)
    {
        switch ($pem->type()) {
            case PEM::TYPE_RSA_PUBLIC_KEY:
                return RSA\RSAPublicKey::fromDER($pem->data());
            case PEM::TYPE_PUBLIC_KEY:
                return PublicKeyInfo::fromPEM($pem)->publicKey();
        }
        throw new \UnexpectedValueException(
            "PEM type " . $pem->type() . " is not a valid public key.");
    }