A judge in Southern California has ruled that a recent federal agents’ search of a man’s cellphone as he was crossing into the United States was entirely lawful.

The case, known as United States v. Caballero, involves a man who was driving into the US from Mexico and attempted to cross the border at Calexico (Imperial County) on September 28, 2015. While at the checkpoint, a dog alerted agents to the presence of narcotics on the man’s car. The government is now accusing Sergio Caballero with importation of more than 33 pounds of methamphetamine and 2.75 pounds of heroin inside the gas tank.

The government brought the criminal case that same day. However, approximately two months later, Caballero’s public defender attempted to suppress the search of the phone, which revealed a photograph of a large amount of cash. The defense attorney, Nathan Feneis, argued that the search of his client’s phone was illegal under the Supreme Court decision Riley v. California. That 2014 decision found that law enforcement generally does not have the right to search a phone belonging to someone who is arrested without a warrant.

However, US District Judge Roger Benitez ruled last Thursday that Riley does not apply in this situation, as Caballero was crossing into the US, and there is a well-known warrantless search exception to the rule at the border.

Judge Benitez cited the 2014 Cotterman decision, which found that an extended and sophisticated forensic analysis of a digital device requires a reasonable suspicion of wrongdoing. (Court documents in Caballero do not specify what type of phone was searched, nor do they indicate whether the phone was locked with a passcode. It seems likely that either there was no passcode or that Caballero unlocked his phone voluntarily.)

As the judge wrote:

With the discovery of undeclared, illicit drugs hidden in Defendant’s vehicle, law enforcement officers had plenty of evidence to meet the heightened standard: reasonable particularized suspicion of unlawful conduct. Officers certainly had reasonable suspicion to search the cell phones carried by Caballero after finding 15 kilograms of methamphetamine and one kilogram of heroin hidden in the gas tank of Caballero’s automobile as he crossed the border. There is no question that a cell phone search, limited as it was in this case, qualifies as a reasonable search at the international border when performed prior to an arrest. Cotterman dictates this much. Since the Cotterman decision is almost on all fours, it controls the outcome of this motion to dismiss. Reviewing the totality of the circumstances, the Caballero cell phone search: (1) took place at a port of entry; (2) was based on reasonable suspicion of criminal activity; (3) was conducted manually and appeared to be a cursory search of the device’s contents; (4) did not involve the application of forensic software; (5) did not destroy the cell phone; (6) was performed in minutes, as opposed to hours or days; (7) was performed upon a device being brought into the country, rather than being taken out of the country; and (8) was performed approximately four hours after Caballero was placed under arrest. Other than the last factor, each of these factors was either similar to or less intrusive than the warrantless search Cotterman decided was reasonable.

However, the judge was well aware that criminal suspects may soon use “more sophisticated encryption” that could foil even the most hard-nosed investigators.

Chris Soghoian, a technologist for the American Civil Liberties Union, offered up these tips for crossing the US border with devices.