Certification delegation from a Rule

Hi, I need to delegate a certification from within a rule. Consider I have the certification object and the identity object(to whom it has to be delegated). Could you please provide a code for the delegation?