Whoever, being in any office which gives him legal authority to commit persons for trial or to confinement or to keep persons in confinement, corruptly or maliciously commits any person for trial or confinement, or keeps any persons in confinement in the exercise of that authority knowing that in so doing he is acting contrary to law, shall be p...