The HBO television series, The Wire, has often been called one of the best TV show of all time but, even when first transmitted, it was curiously dated.

The kenspeckle Baltimore police officers, when they weren't drinking, fighting or dipping into drugs gang assets, used primitive dial-up equipment to tap the calls of their marks.

It also took them an age to get every wire tap. They had to argue the case before a judge and provide evidence of wrong-doing for every recorded conversation, every hacked phone. This was strictly enforced because the detectives knew that, if they were discovered collecting random phone data, even on known criminals, their entire case could collapse.

How far we have come in less than a decade. Intelligence agencies such as the NSA in America and GCHQ are arguably breaking the law on an industrial scale by recording and keeping millions of telephone and email conversations as well as the metadata that goes with them.

If Jimmy McNulty's team had been caught doing that they'd have been on traffic duty for the rest of their careers. The Wire's cops were honourable in their own way but you would never dream of giving them unlimited access to your private communications. But yesterday, the UK Parliament opened the door to our personal data with the Data Retention and Investigatory Powers (Drip) Bill. This measure, compelling phone and internet companies at home and abroad to retain and disclose email and telephone data, was rushed through parliament on the day before the summer recess. There was no serious debate and the media focus was on a major cabinet reshuffle. That told you all you needed to know.

Drip overturns a ruling from the European Court of Justice in April that what the UK police and intelligence people were doing was not lawful. Instead of agreeing that it's a fair cop, the Government, with the connivance of Labour and even the supposedly libertarian Liberal Democrats, decided to pass a get-out-of-jail-free bill. David Cameron claimed that there was a national emergency that justified this extraordinary measure; something to do with paedophiles, terrorists, criminals, Syria and other ogres.

Yesterday's announcement of 660 paedophile arrests seemed timed to coincide with the passage of Drip and give it a spurious justification. But the police do not need blanket access to our data to catch paedophiles. They can apply for warrants to search suspects and their computer equipment and track down perpetrators.

At the very least, this measure should have been debated fully and openly, and it is to the credit of SNP MPs that they alone of the major parties voted against the Drip in the Commons division. Mind you, since the Nationalists have already promised to work hand in glove with the UK intelligence and security agencies after independence, I'm not entirely sure they understand the principles involved here.

Drip could theoretically be challenged in the Scottish courts because the Human Rights Convention is written into the Scotland Act. Human rights groups such as Liberty argue that human rights are being violated.

Drip by drip, they say, the UK is becoming a surveillance state, so perhaps they should play the Scottish card and look for judicial review in a Scottish court. The important point is that, while the technology of surveillance has undergone a quantum leap, the mentality of those using it has not. NSA and GCHQ may be using wonderfully sophisticated computer soft and hardware at the very limits of human understanding.

But the guys using this massive information database are the same old compromised coppers and spooks we know and love, with their prejudices, deceits and ambitions. Some Jimmy McNulty perhaps, sitting at a post-it covered computer screen nosing about in our lives.

Of course, if you've done nothing wrong, you've nothing to fear; or so the apologists for the secret state always tell us. But we know that the NSA has been routinely spying on Muslim leaders and political dissidents in America. And we also know that the British police have used informers and, perhaps, agents provocateur against environmental groups in Britain. Given the UK police's history of miscarriages of justice, and secret service flights of fantasy about non-existent Iraqi nuclear weapons, we must be mad to hand them this power. A few years ago it was discovered that councils were using anti-terror laws to spy on people's bin use.

This is why the law has traditionally given citizens protection from arbitrary arrest and invasion of privacy. But the law is way behind the digital reality as it has never in the past had to deal with a situation in which almost universal surveillance of the population is technically possible. No-one knows the full extent of this because agencies such as the NSA and GCHQ work under cover of secrecy but what we know is serious enough. The accuracy of whistle-blower Edward Snowden's revelations about NSA and GCHQ programmes such as Tempora and Prism hoovering up calls and emails have never been seriously challenged.

There were more revelations this week about how GCHQ had developed a range of new tricks or "weapons" to deal with "terrorists" by doctoring and sending false emails, fiddling with online opinion polls and manipulating Facebook and LinkedIn. The names they give to these actions tells you a lot about the mentality: Angry Pirate, Tracer Fire, Bomb Day, Viper's Tongue. We are seeing state intrusion unprecedented in British history outside wartime. In the days when communication was mostly by post, it would have been regarded as unthinkable for citizens' letters to be routinely opened and copied by the police or by spies.

Mary Queen of Scots had her head chopped off because Walsingham had been collecting and copying her letters to Catholic conspirators. But even Elizabeth 1's spymaster would have baulked at the thought of everyone's letters being intercepted and copied.

Say what you like about the Elizabethans and justice but they abided by the terms of habeas corpus and did not generally seize people and papers without probable cause. The presumption of innocence, freedom from arrest without charge, the right to privacy in communications are age old liberties Britain gave to the world after Magna Carta. These freedoms are being breached without serious discussion of the implications.With the 800th anniversary of Magna Carta approaching, we need to go back to basics. There should be a new defence of digital habeas corpus. The body of digital information on us should not be intercepted and held by authorities without evidence of wrong-doing.

Our communications data should be held for a limited period only, and we should have the right to be informed when and why. Above all, we need a codified bill of rights so that parliamentary coups like Drip cannot happen without the constitutional implications being addressed. We cannot allow here-today, gone-tomorrow politicians to play fast and loose with our civil liberties.