Florida is unconstitutionally enforcing its ban on voting by ex-felons, an Obama-appointed federal judge ruled Thursday in a decision that could potentially upend this year’s elections.

In a scathing ruling that included a sharp rebuke to Republican Gov. Rick Scott’s administration, U.S. District Judge Mark Walker said the state's current process to restore voting rights — which can take years — is unconstitutional primarily because it is handled unfairly.

"A person convicted of a crime may have long ago exited the prison cell and completed probation," Walker wrote. "Her voting rights, however, remain locked in a dark crypt. Only the state has the key — but the state has swallowed it."

John Tupps, a spokesman for Scott, defended the process and suggested that an appeal was likely.

"The governor believes that convicted felons should show that they can lead a life free of crime and be accountable to their victims and our communities," Tupps said. "While we are reviewing today's ruling, we will continue to defend this process in the court."

"The governor believes that convicted felons should show that they can lead a life free of crime and be accountable to their victims and our communities." — John Tupps, spokesman for Florida Gov. Rick Scott

Walker’s 43-page ruling does not mean that Florida’s automatic ban on voting by ex-felons – which has been enshrined in the state’s constitution for decades – is itself improper.

In fact, Walker said in his ruling that the automatic ban is legal, but added the process can't be arbitrary, or swayed by partisan politics.

He noted, for example, that Scott and the Cabinet restored voting rights to a white man who had voted illegally but told Scott that he had voted for him. Walker also pointed out that others who acknowledged voting illegally — but were black — had their applications turned down.

Florida's current process for restoring voting rights to felons who have completed their sentences is a slow one. It requires a hearing, and applicants are often denied. Shortly after taking office in 2007, then-Gov. Charlie Crist, a Republican, convinced two of the state's three Cabinet members to approve rules that would allow the parole commission to restore voting rights for non-violent felons without a hearing. Within a year, more than 100,000 ex-felons were granted voting rights.

But Scott and state Attorney General Pam Bondi pushed to end automatic restoration of voting rights as one of their first acts upon taking office in 2011. Most former felons have to wait at least five years before they can even apply to have their rights restored. Over the last seven years less than 3,000 former prisoners have had their rights restored.

Walker’s ruling does not set out a remedy for Florida’s violation. The judge said he will decide soon what Florida should do to fix the process.

A voting rights organization sued Scott last year on behalf of several people who had completed their prison sentences but had their request for voting rights turned down.

The ruling comes just months before Florida voters will be asked to alter the current ban. Backers of a constitutional amendment last week won a place on the November 2018 ballot. If 60 percent of voters approve, most former prisoners would have their rights automatically restored.

The Associated Press contributed to this report.