switch truncate_digest_for_ecdsa to context manager

Also adds a docstring to fix #1335