Apple has formally laid out its legal defense against a court order forcing it to help the FBI unlock the iPhone of one of the San Bernardino shooters.

In a filing Thursday, Apple argued the court order violated its constitutional rights under the First and Fifth Amendments.

The U.S. Department of Justice had asked Apple to write special code that would enable the FBI to bypass the iPhone's lock-out function, which would wipe the only key to information on the device after 10 wrong passcode attempts.

In its filing, released early before a Friday deadline, Apple called the "conscription" of an American company to do the government's bidding "unprecedented."

"Nothing in federal law allows the courts, at the request of prosecutors, to coercively deputize Apple and other companies to serve as a permanent arm of the government's forensics lab," Apple stated in court documents.

It said the government's request violated the company's Fifth Amendment right to be free from "arbitrary deprivation of its liberty by government."

It also said that the court's request violated its First Amendment right to free speech -- arguing that writing code is protected speech under the Constitution. "When Apple designed iOS 8, it wrote code that announced the value it placed on data security and the privacy of citizens by omitting a back door," the filing stated.

If the government succeeds in having Apple "write new software that advances its contrary views," then Apple's free speech is violated.

In repeated public appearances, Apple representatives have said that the government's demands would ultimately make iPhones less safe. If the company creates a "back door" for law enforcement, it would also be available for criminals and other bad actors.

"The government wants to compel Apple to create a crippled and insecure product," Apple said in court documents.

The government has argued that its request is for this one iPhone alone, and it wouldn't create vulnerabilities for the millions of other iPhones.

Apple disagrees: "This is not a case about one isolated iPhone."

The company said it fears the government will repeatedly force Apple to create code for future criminal investigations, potentially making it churn out code on demand, a request it calls "unreasonably burdensome."

On a call with reporters, an Apple executive said the company didn't know for sure how long it would take, noting it had never done anything like this before.

But in the filing, Apple revealed it could meet the FBI's demand by assigning six to 10 engineers, working two to four weeks.

In written testimony, an Apple employee nicknamed the software "GovtOS."

In a response Thursday afternoon, the Department of Justice said Apple is only now raising legal objections to something it never had a problem with before.

Justice Department spokeswoman Melanie Newman said the only thing that's changed is "Apple's recent decision to reverse its long-standing cooperation in complying with All Writs Act orders."

Apple vs. FBI: A timeline

The government will have an opportunity to respond to Apple by March 10, and Apple can offer one final reply by March 15.

Attorneys for Apple and the government are due in court on March 22. A federal magistrate-judge will hear their arguments and make a ruling soon after.

The tense fight between Apple (AAPL) and the government have set off a fierce debate about security, privacy and encryption.

No matter what the magistrate-judge ultimately rules, it is widely expected that the case will be appealed, perhaps up to the Supreme Court.

Other tech companies, including Amazon (AMZN), Facebook (FB), Microsoft (MSFT) and Twitter (TWTR) plan to come forward in support of Apple's case through an amicus brief.

CNN's Hope King contributed to this report.