Clarify CMS_decrypt behaviour.
Extension checking fixes.

When looking for an extension we need to set the last found
position to -1 to properly search all extensions.

PR#3309.
refactoring: extract function apply_msg_callback

in order to avoid nasty bugs in the future caused by copy and paste
Remedy a little bit this lousy, lousy programming style
Follow convention: no space after parenthesis
Compute heartbeat size by a function
wip
refactor out payload read