Static Analysis for the Pi-Calculus with Applications to Security