In any criminal investigation or in any criminal action or action for revocation of suspended sentence or probation in the circuit or magistrate court or in a final proceeding to revoke a parole, if it is satisfactorily shown that the defendant or detained person does not have sufficient money, credit, or property to employ counsel and pay for the necessary expenses of his representation, the judge of the circuit court or the magistrate shall, upon the request of the defendant, assign, at any time following arrest or commencement of detention without formal charges, counsel for his representation, who shall appear for and defend the accused upon the charge against him, or take other proper legal action to protect the rights of the person detained without formal charge.
In each case, the indigent person, subject to the penalties for perjury, shall certify in writing or by other record such material factors relating to his ability to pay as the court prescribes.
SDCL 23A-40-6