A woman accusing Bill Cosby of sexual assault is entitled to any documents or emails the comedian's criminal lawyer shared with a former prosecutor who has become a key defense witness, a federal judge ruled Friday.

Former prosecutor Bruce Castor has stepped forward since Cosby's arrest last year to testify that he had promised Cosby a decade ago that he would never be charged in the case.

A judge refused to dismiss the charges on those grounds, but Cosby appealed and remains free on $1 million bail.

Click here to subscribe to FOX411’s YouTube channel

The ruling Friday came in the related defamation lawsuit that former Temple University employee Andrea Constand filed against Castor. Castor has said Constand changed her story about her encounter with Cosby at his suburban Philadelphia home in 2004 before she sued Cosby for damages.

"If the allegations in the civil complaint were contained with that detail in her statement to the police, we might have been able to make a case out of it," he told The Associated Press last year, defending his decision not to prosecute as dozens of other accusers came forward.

Castor testified for the defense for an entire day as Cosby's lawyers sought to have the sex assault charges dropped in March. Constand on Friday won the right to see any police reports, emails or other correspondence that Cosby lawyer Brian McMonagle had shared with him.

U.S. District Judge Eduardo Robreno, presiding at Friday's hearing, is the same judge who agreed last year to unseal excerpts from Cosby's testimony in Constand's 2005 lawsuit. In the excerpts, Cosby, who's been married for more than 50 years, acknowledged a series of affairs and getting sedatives to give women he hoped to seduce. That led Castor's successor to reopen the criminal case.

Cosby, meanwhile, has sued Constand for talking to police last year despite their confidential settlement of that lawsuit.

Constand's lawyers want the confidentiality agreement voided because of remarks made by Cosby's camp. Robreno put that matter on hold.

The Associated Press generally doesn't identify people who say they are victims of sexual assault unless they come forward publicly, as Constand has done.