There is little dispute that President Donald Trump has the basic authority to revoke security clearances for current and former federal officials, as he did last week in the case of former CIA Director John Brennan and has threatened to do for several others who have criticized him.

The rules for security clearances are governed by executive order, not law, and the president is the head of the executive branch.

But how far does that power extend? Are there any limits to the president’s ability to restrict a person’s access to classified information for any reason he chooses?

The answer is unclear, say national-security lawyers and experts on secrecy laws, and it might take a lawsuit by Brennan to settle the question once and for all. “It has never been tested in court,” said Jeffrey Smith, a former general counsel for the CIA and a longtime national-security lawyer. “It’s not clear that the president is acting legally.”

Trump revoked Brennan’s clearance last week, citing in a statement his “erratic conduct and behavior.” Brennan, who served as a top counterterrorism adviser and then CIA director under former President Barack Obama, has been one of the most vociferous critics of Trump in the tight-knit community of former senior intelligence and national-security officials. But in a subsequent interview, the president suggested that Brennan’s involvement in the intelligence assessment that led to the federal investigation into whether Trump’s campaign colluded with the Russians played into his decision.

The president is also considering revoking the clearances of other top national-security officials who served Obama and who have been critical of him, including General Michael Hayden, General James Clapper, former FBI Director James Comey, former Deputy Attorney General Sally Yates, and former Nation-Security Adviser Susan Rice. One official on Trump’s list of potential targets is Bruce Ohr, who is currently serving in the criminal division of the Justice Department. Ohr has been the subject of conspiracy theories on the right owing to the employment of his wife as a contractor for Fusion GPS, the research firm that helped compile the dossier containing explosive but unverified reports about Trump’s activities in Russia several years ago.

Trump’s actions and threats have alarmed former high-ranking government officials in both parties, who see them as capricious attempts to silence the president’s critics. “We all agree that the president’s action regarding John Brennan and the threats of similar action against other former officials has nothing to do with who should and should not hold security clearances—and everything to do with an attempt to stifle free speech,” wrote more than a dozen such officials in an open letter last week.

Traditionally, decisions to suspend or revoke security clearances are handled at the agency level, far below the president and other senior White House officials. Under a process dictated by a 1995 executive order signed by President Bill Clinton, people who have their clearances suspended or revoked are entitled to a written explanation and an opportunity to appeal the decision. Trump’s unilateral decision to revoke Brennan’s appears to have entirely short-circuited that process.

“To my knowledge, it’s entirely unprecedented,” said Steven Aftergood, the director of the Project on Government Secrecy for the Federation of American Scientists. “Presidents do not get involved in security-clearance decisions. It’s way below their pay grade, so to speak.”

Neither Aftergood nor Smith could recall a president ever personally revoking a security clearance as Trump did. For the closest parallel, Smith had to go back more than a half century, to when the physicist J. Robert Oppenheimer lost his security clearance in 1954 after acknowledging associations with the Communist Party a decade earlier. Oppenheimer’s case, Smith said, was a “politically rigged” response to his opposition to U.S. nuclear programs at the time, including the development of the H-bomb.

“It’s now regarded as a low point of the McCarthy era,” he said.

Yet even Oppenheimer received a semblance of due process before losing his clearance. Whether Brennan will have an opportunity to meaningfully appeal Trump’s decision is unclear.

Because the appeals process stays within the executive branch, his chances for success would appear to be nil. “There’s no one in the executive branch who is a higher authority than the president,” Aftergood said. “It’s not clear to whom the decision would be appealed.”

Brennan’s other option—one that he says he is considering—is to take the president to court and seek an injunction while he presses his case on the grounds that Trump infringed on his First Amendment right to free speech. “I am going to do whatever I can personally to try to prevent these abuses in the future,” Brennan said Sunday on Meet the Press, “and if it means going to court, I will, I will do that.” Nick Shapiro, a spokesman for the former CIA director, told me he had not made a decision as to whether to sue.

Hayden, who served as the director of the National-Security Agency and then the CIA in the George W. Bush administration, said he and Brennan have heard from lawyers who offered to bring a case challenging the president’s power. (Hayden has not yet had his clearance revoked.)

“Was this so abnormal, so out of the normal turn of events, so absent of process, that it was an illicit use of what was, and is, an inarguable presidential authority?” Hayden told me, summarizing what a lawsuit would seek to answer.

Trump and his lawyer, former New York City Mayor Rudy Giuliani, have tried to goad Brennan into filing a lawsuit, and the president has acknowledged that he was elevating Brennan in part because he relished a fight with him.

But some national-security lawyers want Brennan to sue too, even if his chances of victory are slim. “I think the case law is really clear from a practical, realistic standpoint that Brennan would not be able to make any substantive progress in a lawsuit,” said Mark Zaid, a national-security lawyer who has experience representing whistle-blowers and federal officials who have had their clearances suspended or revoked. He cited a 1988 Supreme Court case in which the justices confirmed that the executive branch has broad authority to deny someone a security clearance on national-security grounds.

But, as Smith wrote last week in The New York Times, that case was decided on a procedural basis, not on the First Amendment grounds on which Brennan would presumably base a lawsuit. And Zaid said he would eagerly represent Brennan in such a case, no matter how much of a long shot it was. “When it comes to the national-security arena, many times where we bring a case, we’re not bringing a case with an expectation of a win,” he told me. “In fact, we expect to lose, quite frankly, a majority of the time.”

“But,” Zaid continued, “as long as we’re not bringing a frivolous case, we can bring that case with the hope that we can raise the issue that is at play.”

The goal of a lawsuit would be to get the 1988 decision overturned, but there are some lawyers who worry that if Brennan were to bring a case and lose, it would further empower Trump and future presidents to weaponize the granting and revocation of security clearances.

Smith said the onus was on Congress to pass a law clarifying and codifying the process for handling clearances, and there is some movement in the Senate to do just that. Democratic Senator Mark Warner of Virginia has introduced an amendment to a pending defense-appropriations bill that would bar federal funds from being spent on revoking clearances unless the process outlined in the 1995 executive order is strictly followed. In other words, it would block Trump from stripping clearances without first giving current and former officials the benefit of due process. On Tuesday, Senator Jeff Flake of Arizona, one of Trump’s most outspoken GOP critics, said he would co-sponsor Warner’s proposal.

Zaid and Smith each mentioned one other possibility: The CIA, which holds Brennan’s clearance, could stand up to Trump and either refuse to revoke his clearance or insist that he receive due process before doing so. In the final line of Trump’s statement last week, the president said he was directing staff at the National-Security Council to “make the necessary arrangements with the appropriate agencies to implement this determination.” The language suggests that the revocation did not occur by fiat but would have to be done bureaucratically.

More than a week after Trump’s statement, Brennan has received no written or verbal communication from the CIA about the status of his clearance, raising the question whether, as a technical matter, it has been revoked at all. Asked whether Brennan’s security clearance had formally been revoked, a CIA spokeswoman replied only: “The CIA does not comment on individual security clearances.”

While a decision to strip the clearance of a current federal official such as Ohr could be tantamount to termination, the impact from a practical standpoint for former officials would be limited. Without a security clearance, Brennan would be unable to fully consult with his successors, visit the CIA unescorted, or participate in meetings either in the public or private sector in which classified information is discussed. Trump and his allies have accused him and other critics of trying to “monetize” their clearances by acting as paid television commentators. Others have suggested that Brennan’s employment opportunities could be limited because top jobs with defense contractors and other Beltway landing spots require clearances.

But Aftergood said those concerns were overstated. “It’s not their access to information. It’s their access to people and their name recognition,” he said. “Brennan’s career as a TV commentator is unlikely to be curtailed as a result of this episode. It may even be helped.”

Hayden acknowledged that the personal injury of losing a clearance would not be cause for Brennan to sue. “If he were to do it,” he told me, “it would be for the higher principle involved.”