Fortunately the U.S. has not slid that far down the slope yet. What you are referring to are known as "ex post facto" laws and thankfully they are still considered unconstitutional in this country (at least for now). If it was legal when you did it but is made illegal after the fact, you cannot constitutionally be charged with violating the law for your earlier action.
_________________________
"It's a legal system, not a justice system!"