A federal judge in Brooklyn says the FBI cannot force Apple to open a locked iPhone used by a suspected drug dealer.

The ruling is a boost to Apple in the public opinion war with the federal government over access to locked devices. Though it is not binding on a judge in California who is now considering the separate case of access to a locked iPhone used by one of the San Bernardino attackers, it gives the company a leg up, and Apple will be sure to cite it in that ongoing dispute.

The massacre in San Bernardino, Calif., left 14 people dead, and investigators searching for answers.

U.S. Magistrate Judge James Orenstein said the FBI could not compel Apple to unlock the phone in the Brooklyn case, because Congress specifically considered and rejected a bill that would require companies like Apple to make the data on a locked iPhone available to law enforcement.

What the government could not achieve in Congress, the judge said, it cannot now get from the courts. "The relief the government seeks is unavailable because Congress has considered legislation that would achieve the same result but has not adopted it.

Related: Why Are Apple and the FBI Battling Over an iPhone?

"It is also clear that the government has made the considered decision that it is better off securing such crypto-legislative authority from the courts," Orenstein said, "rather than taking the chance that open legislative debate might produce a result less to its liking."

Orenstein wrote that finding a balance between the competing interests of the governments investigative powers and unwarranted intrusion was a debate needs to take place sooner rather than later.

Related: Apple vs. FBI: Feds Have More Support Than Tech Giant, Survey Says

Byers Market Newsletter Get breaking news and insider analysis on the rapidly changing world of media and technology right to your inbox. This site is protected by recaptcha

"The debate must happen today, and it must take place among legislators who are equipped to consider the technological and cultural realities of a world their predecessors could not begin to conceive," the judge wrote in the 50-page decision.

Judge Orenstein also agreed with Apple's contention that what the government wanted in the Brooklyn drug dealer case was too much of a burden on the company, another argument the company makes in the San Bernardino case.

"The assistance the government seeks here — bypassing a security measure that Apple affirmatively markets to its customers — is not something that Apple would normally do in the conduct of its own business and is, at least now, plainly offensive to it," Orenstein wrote.

The judge "completely sides with Apple," a senior Apple executive said in a conference call with reporters after the ruling. "It's the first case any court has had to directly and specifically address" the issues involved.

Related: Apple CEO: Helping Unlock iPhone Would Be 'Bad for America'

A Justice Department said in a statement that the government was disappointed and will seek review of the decision.

"Apple expressly agreed to assist the government in accessing the data on this iPhone — as it had many times before in similar circumstances — and only changed course when the government's application for assistance was made public by the court," the DOJ said. "This phone may contain evidence that will assist us in an active criminal investigation and we will continue to use the judicial system in our attempt to obtain it."

"This is a victory for privacy, security, and common sense," said Alex Abdo, staff attorney with the ACLU Speech, Privacy, and Technology Project. "The government should not be able to run to court to get the surveillance power that Congress has deliberately kept from it. The future of digital privacy also hangs in the balance. If the government can force companies to weaken the security of their products, then we all lose."

Orenstein's ruling was expected, however, because he raised similar concerns in a preliminary discussion of the case issued last October.

At the time, Orenstein invited Apple to challenge the government's use of a 1789 law to compel Apple to help it recover iPhone data in criminal cases. Since then, lawyers say Apple has opposed the requests to help extract information from over a dozen iPhones in California, Illinois, Massachusetts and New York.

Monday's ruling comes a day before FBI Director James Comey and Apple's General Counsel, Bruce Sewell, appear before a congressional hearing.