Updated

The former district attorney who declined a decade ago to bring sex-crime charges against Bill Cosby testified Tuesday that he believes his decision prohibits his successors from ever prosecuting the comedian.

But he also said he hopes he is wrong.

Former Montgomery County District Attorney Bruce Castor took the stand as part of a bid by Cosby's lawyers to get the case against the TV star thrown out because of what they say is a non-prosecution agreement from Castor.

The current district attorney, Kevin Steele, has said there is no record of any such agreement.

Cosby, 78, was arrested and charged in December with drugging and violating former Temple University athletic department employee Andrea Constand at his suburban Philadelphia mansion in 2004. He could get up to 10 years in prison if convicted.

Castor said Tuesday that he believed Constand was violated, but that proving it would have been problematic because of serious flaws in the case, and so he declined to bring charges in 2005.

He said he made the decision as a representative of the state and he believes his decision will last “For all time, yes."

Castor suggested that Cosby and his lawyer at the time had the same understanding, because Cosby later agreed to testify without invoking his Fifth Amendment right against self-incrimination in a lawsuit brought against him by Constand.

"Cosby would've had to have been nuts to say those things if there was any chance he could've been prosecuted," Castor said, referring to the damaging testimony unsealed last summer.

Castor said he hoped, correctly, at the time that the decision not to prosecute would free the comedian to testify in the lawsuit and help Constand win damages.

"I thought making Mr. Cosby pay money was the best I was going to be able to set the stage for," he told the courtroom. "I was hopeful that I had made Ms. Constand a millionaire."

She eventually settled for an undisclosed amount.

Castor said he relayed word to Cosby's then-attorney, Walter Phillips, that Cosby would not be charged. However, Castor said the two lawyers did not have "an agreement" that Cosby would testify in exchange for not being prosecuted.

Phillips is now dead.

Steele, who is pursuing the case, has said Cosby would need an immunity agreement in writing to get the case thrown out. He has said he has no evidence one exists.

While Castor was called as witness by Cosby's side, the former DA told Cosby’s lawyer, Brian McMonagle, he is rooting for the prosecution.

"Let’s be clear Mr. McMonagle, I'm not on your team here,” he said. “I want them to win."

In a barrage of allegations that have destroyed Cosby's image, dozens of women have accused the former TV star of drugging and sexually assaulting them since the 1960s. But this is the only case in which he has been criminally charged.

The unsealing of the testimony from Constand's lawsuit prompted Castor's successors to reopen the case and ultimately charge Cosby.

Cosby admitted in the deposition that he had affairs with young models and actresses, that he obtained quaaludes to give to women he wanted to have sex with, and that he gave Constand three pills at his home. He said he reached into her pants but insisted it was consensual.

Castor defended his decision not to bring charges, testifying that he saw Constand's year-long delay in reporting the allegations, inconsistencies in her statements and her contact with a lawyer before going to police as problematic.

Castor said Constand's delay was of "enormous significance" in his consideration of the case. He said it thwarted his ability to test her hair or fingernails for evidence she was drugged.

Still, Castor said, he investigated the case thoroughly because he wanted to show authorities in Constand's native Canada that celebrities don't get preferential treatment in America.

It was not immediately clear when Common Pleas Judge Steven T. O'Neill would rule.

The Associated Press contributed to this report.