An advocate general for the EU's Court of Justice released a legal opinion Tuesday outlining when telecommunications companies should be able to hand over individual's data to security agencies.

Henrik Saugmandsgaard Oe wrote that in general, a data retention obligation "may be compatible with EU law" as long as it meets certain criteria, the court said in a summary statement.

The EU had mandated the retention of private phone and internet data - such as the location, time and frequency of communications between individuals - as part of anti-terrorism measures adopted in 2006 after bombing attacks on subways in Madrid and London.

But the European Court of Justice struck down the law in 2014, finding that it breached citizens' fundamental rights.

The top court has now been asked by judges in Britain and Sweden for clarification whether an EU country can legally compel telecommunications firms to retain data for law enforcement purposes.

'Data retention is a kind of mass surveillance'

But there would be limits - including national legislation and regulation - as well as guarantees that data retention would be proportionate to the perceived threat to society. Germany has already passed its own national law on data retention despite fervent opposition from Berlin's own data commissioner.

"The general obligation to retain data must be strictly necessary to the fight against serious crime," the court wrote in a summary of Oe's legal opinion.

The legal opinion is not binding - it is only the view of one of 10 legal advocate generals. But judges often follow the legal advice of their staff counsel.

Digital privacy and the practice of data retention and mass surveillance is a highly important issue due to the ubiquitous presence of digital communications in daily life. In Europe, the issue became political following the Snowden leaks in 2013 that proved surveillance had been carried out widely in Europe through close coordination between European and US intelligence agencies.

A final ruling by the Luxembourg-based court is not expected for several months.

jar/kms (dpa, European Court of Justice)