Function parses an ASN.1 encrypted message and extracts/decrypts 
            the original message.

    :param data_to_verify: 
        A byte string of the data to be verified against the signature. 

    :param signature: A CMS ASN.1 byte string containing the signature.
    
    :param verify_cert: The certificate to be used for verifying the signature.

    :return: The digest algorithm that was used in the signature.

def verify_message(data_to_verify, signature, verify_cert):
    """Function parses an ASN.1 encrypted message and extracts/decrypts 
            the original message.

    :param data_to_verify: 
        A byte string of the data to be verified against the signature. 

    :param signature: A CMS ASN.1 byte string containing the signature.
    
    :param verify_cert: The certificate to be used for verifying the signature.

    :return: The digest algorithm that was used in the signature.    
    """

    cms_content = cms.ContentInfo.load(signature)
    digest_alg = None

    if cms_content['content_type'].native == 'signed_data':
        for signer in cms_content['content']['signer_infos']:

            signed_attributes = signer['signed_attrs'].copy()
            digest_alg = signer['digest_algorithm']['algorithm'].native

            if digest_alg not in DIGEST_ALGORITHMS:
                raise Exception('Unsupported Digest Algorithm')

            sig_alg = signer['signature_algorithm']['algorithm'].native
            sig = signer['signature'].native
            signed_data = data_to_verify

            if signed_attributes:
                attr_dict = {}
                for attr in signed_attributes.native:
                    attr_dict[attr['type']] = attr['values']

                message_digest = byte_cls()
                for d in attr_dict['message_digest']:
                    message_digest += d

                digest_func = hashlib.new(digest_alg)
                digest_func.update(data_to_verify)
                calc_message_digest = digest_func.digest()

                if message_digest != calc_message_digest:
                    raise IntegrityError('Failed to verify message signature: '
                                         'Message Digest does not match.')

                signed_data = signed_attributes.untag().dump()

            try:
                if sig_alg == 'rsassa_pkcs1v15':
                    asymmetric.rsa_pkcs1v15_verify(
                        verify_cert, sig, signed_data, digest_alg)
                elif sig_alg == 'rsassa_pss':
                    asymmetric.rsa_pss_verify(
                        verify_cert, sig, signed_data, digest_alg)
                else:
                    raise AS2Exception('Unsupported Signature Algorithm')
            except Exception as e:
                raise IntegrityError(
                    'Failed to verify message signature: {}'.format(e))

    return digest_alg