Topological signatures of interstellar magnetic fields - I. Betti numbers and persistence diagrams