The Justice Department on Wednesday vigorously defended the appointment of Matt Whitaker to serve as acting attorney general, saying that the selection was entirely legal and that the White House was given that advice beforehand.

Steven Engel, assistant attorney general for the Office of Legal Counsel, said in a 20-page opinion that his office told the White House — before Whitaker was appointed — that the president "could designate a senior Department of Justice official, such as Whitaker, as acting attorney general."

That advice was offered "after the White House asked what the president's option would be in the event the office of attorney general was vacant and who might be eligible to serve," a senior Justice Department official said.

The opinion came the day after the state of Maryland urged a federal judge to rule that Whitaker's appointment violated the Constitution and a federal law. The judge has yet to act on the state's request for expedited consideration of its motion.

President Donald Trump named Whitaker acting attorney general under a law known as the Federal Vacancies Reform Act, which allows a president to fill a vacant cabinet position with a senior employee of the affected agency. Whitaker had been the chief of staff to Jeff Sessions, who was forced to resign as attorney general last week.

But Maryland said a separate federal law governs what happens when the office of attorney general is vacant. It provides that the deputy attorney general takes over, which would be Rod Rosenstein.

Wednesday's Justice Department legal guidance said courts have previously held that the president has the option of either using the Vacancies Reform Act to fill a vacant cabinet-level job or allowing the deputy to take over.

The Justice Department's Office of Legal Counsel has weighed in before on the president's legal authority to use the Vacancy Act to bypass the department's normal order of succession and pick someone not in line to move up. But that opinion, written in 2007 after the resignation of Alberto Gonzales as attorney general, assumed that the president's pick already held a Senate-confirmed job.

Maryland also argued that the appointment of Whitaker violates a provision of the Constitution that specifies that top positions in the government can be filled only by someone who has been confirmed by the Senate. Whitaker's appointment bypassed that process.

But Engel's opinion said the Justice Department has identified over 160 times throughout U.S. history when presidents appointed non-Senate confirmed government officials to serve in high level positions. In recent years, the opinion said, such appointments were made by Presidents George W. Bush and Barack Obama.

The opinion said that while courts have held that the Constitution requires principal officers to be confirmed by the Senate, "it does not follow that Acting Attorney General should be understood to be one," because the person appointed to serve in that capacity is not in a "continuing and permanent" position.

Maryland's motion came in a lawsuit over the future of Obamacare, seeking a ruling that the Affordable Care Act remains enforceable despite attempts by the Trump administration to shut it down. It named several defendants, including Sessions, who was attorney general when the case was filed in September. With Sessions gone, Maryland said, the judge overseeing the lawsuit should declare that the attorney general defendant cannot be Whitaker.

Harvard law professor Laurence Tribe called the Maryland lawsuit entirely legitimate.

"They're saying that since Jeff Sessions is no longer the attorney general, they can't be expected to engage in this battle against a kind of cloud that might just go pop the moment someone concludes, as they should, that Matt Whitaker is not constitutionally qualified to play that role," Tribe said.

"If they're right about that, and I think they are, this is the way to have it declared."