Every attorney general, state's attorney, or other public prosecutor, or any attorney directly or indirectly connected therewith as a partner, who receives directly or indirectly from or on behalf of any defendant any valuable consideration, upon any understanding or agreement, express or implied, having relation to the defense of any action or proceeding, civil or criminal, for or in behalf of the public against such defendant, which action or proceeding is then under preparation, pending, or having theretofore been prosecuted by such attorney, is guilty of a Class 2 misdemeanor. Nothing in this section shall prohibit any attorney from acting as such on his own behalf when prosecuted either civilly or criminally.
SDCL 16-18-29