Image copyright Getty Images Image caption Kenny MacAskill said the emergency legislation "potentially impinges" on Scots law

Scottish Justice Secretary Kenny MacAskill has accused the UK government of a "lack of prior consultation" over surveillance powers.

Emergency powers to enable police and security services to continue to access phone and internet records are being rushed through the UK Parliament.

The move has the backing of the three main Westminster parties.

Mr MacAskill said the legislation could affect Scots law and matters devolved to the Scottish government.

Prime Minister David Cameron defended the move in a joint news conference with Deputy Prime Minister Nick Clegg, saying it was about maintaining existing capabilities - not introducing new snooping laws.

An EU directive requiring phone and internet companies to retain communications data - when and who their customers called, texted and emailed but not what was said - for a 12-month period was ruled unlawful in April by the European Court.

Mr Cameron claimed the emergency legislation, which would mean firms can retain data for 12 months, was needed to prevent companies fearing legal challenges destroying the information within weeks, meaning police and the security services would not be able to access it.

MacAskill said: "We are disappointed at the lack of prior consultation and discussion from UK government on today's announcement given how much this legislation potentially impinges on areas of Scots law that are clearly devolved and under the jurisdiction of the Scottish government or our law enforcement agencies, including the Crown Office and Procurator Fiscal Service.

Image copyright BBC News Image caption David Cameron and Nick Clegg held a joint news conference on the emergency legislation

"While the retention of communications data is currently a reserved matter, the Scottish government takes the safety and security of our communities extremely seriously.

"In an independent Scotland, this government will set out clear arrangements for investigatory powers, updating existing legislation where necessary.

"This will ensure that law enforcement agencies have the powers that they need to do their job and keep Scotland safe, while also clarifying the limit of those powers and the extent of the controls over them."

Mr Cameron said: "We face real and credible threats to our security from serious and organised crime, from the activity of paedophiles, from the collapse of Syria, the growth of Isis in Iraq and al Shabab in East Africa.

"I am simply not prepared to be a prime minister who has to address the people after a terrorist incident and explain that I could have done more to prevent it."

He stressed that the measures were about "plugging holes" in the legislation but were not about any "new obligations for phone and internet companies, nor any new intrusions on civil liberties".

The UK government claimed the planned legislation would contain safeguards, including the creation of a new oversight board and a "sunset clause" ensuring the powers end in 2016, enabling a longer and wider debate about what would replace them.