Indemnity Agreements: Res Gestae Atque Gerendae

Can someone be indemnified against an unlawful act?  California Civil Code Section 1668 would seem to say "no":

All contracts which have for their object, directly or indirectly, to exempt any one from responsibility for his own fraud, or willful injury to the person or property of another, or violation of law, whether willful or negligent, are against the policy of the law.

Section 1668 is located within a part of the Civil Code defining various types of unlawful contracts.  Thus, the following section provides "Every contract in restraint of the marriage of any person, other than a minor, is void."  A separate part of the Civil Code addresses indemnity agreements.  That part makes a distinction between acts done (res gestae) and acts to be done (res gerendae).  With respect to future acts, Section 2773 provides:

An agreement to indemnify a person against an act thereafter to be done, is void, if the act be known by such person at the time of doing it to be unlawful.

With respect to acts done, Section 2774 provides:

An agreement to indemnify a person against an act already done, is valid, even though the act was known to be wrongful, unless it was a felony.

But how are these two statutes to be reconciled with Section 1668?  According to the California Supreme Court, these statutes don't need to be reconciled because they concern different subjects: "Section 1668 applies to contractual exemptions from liability, not to indemnity contracts." Safeco Ins. Co. v. Robert S., 26 Cal. 4th 758, 767 (Cal. 2001).