Former CIA officer Jeffrey Sterling leaves the federal courthouse in Alexandria, Va., in 2015. (Kevin Wolf/AP)

A federal appeals court panel on Thursday largely affirmed the convictions of former CIA officer Jeffrey Sterling, who was found guilty in 2015 of giving classified information to a journalist in a case that free-press advocates worry may have set a precedent for compelling reporters to reveal their sources.

A three-judge panel with the U.S. Court of Appeals for the 4th Circuit upheld all but one of Sterling’s convictions and determined that because his 42-month sentence could have applied to any single count of which he was found guilty, there was no need to take further action.

The court vacated one of the convictions because, in the view of a majority of the judges, prosecutors had not adequately proved the offense had taken place in the Eastern District of Virginia, where the case was tried. But the judges rejected Sterling’s arguments on the other counts, and the third member of the panel wrote that he would have affirmed the case entirely.

Sterling’s wife, Holly, said she talked to her husband Thursday about the outcome, and, “All hope that he had is gone.”

“We’re both just shocked,” she said. “It was like hearing the verdict read all over again, for me. I really don’t understand it. There was absolutely no proof.”

Sterling said she and her husband in the past had considered taking the case to the Supreme Court, but they did not discuss on Thursday whether they would do so and wanted to first talk to their lawyers about it.

Edward B. MacMahon Jr., one of Jeffrey Sterling’s attorneys, said, “I’m obviously disappointed in the ruling, and I still believe in his innocence.” Barry J. Pollack, another of his lawyers, said that although it was technically possible Sterling could appeal to the Supreme Court, “obviously the odds are very long that the Supreme Court is going to take any given case, so he’ll have to make a decision as to whether he’ll want to take a shot at that or not.”

Sterling was convicted in January 2015 of giving classified information to journalist and author James Risen about a highly secretive operation to give faulty nuclear plans to Iran — details of which Risen later published in his 2006 book, “State of War.”

The way prosecutors told it, Sterling was upset at the CIA and trying to get revenge when he talked to Risen about the matter. He had been fired from the agency in the early 2000s, had sued over alleged discrimination and also sparred with officials about publishing a memoir describing some of his work.

Sterling steadfastly denied he was a source for Risen. The case against him was largely circumstantial; there were no recorded phone calls or captured email exchanges to prove he had leaked information. But prosecutors successfully argued that Sterling was the only potential source who had a relationship with Risen, and that he knew all of the information from the chapter at issue.

The case was notable not just in its own right, but also because it spawned a First Amendment confrontation between Risen and the Justice Department. Prosecutors initially sought to compel Risen to take the witness stand at trial so they could ask him about his sources, and an appeals court gave them the right to do so.

In doing so, the court effectively ruled that neither the First Amendment nor common law offers protection to journalists who promise anonymity to their sources from having to testify about them in criminal proceedings — a precedent that might take on new significance if President Trump and Attorney General Jeff Sessions follow through on their promise to root out leakers with criminal charges.

In Sterling’s case, the department ultimately decided not to put Risen on the stand. He had vowed to go to jail before he would reveal any sources.

In his appeal, Sterling had argued that the venue of the case in the Eastern District of Virginia was improper and that the judge on the case improperly admitted evidence showing he had retained classified documents in the past. The majority of the judges agreed with him on only one point: Prosecutors, they said, had not provided enough evidence to show that Sterling transmitted a letter about the classified program to Risen in the Eastern District of Virginia.

Sterling, now 50, is scheduled to be released from prison next June, online court records show, though Pollack said he hoped to be moved to a halfway house before then, possibly in December. Sterling told The Washington Post in messages for an article published last year that he was struggling to adjust to life behind bars.

“I am doing my best,” he wrote at the time, “to hang on.”