<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sign(self, cert, pkey, digest_type=None, data=None, flags=Flags.BINARY):
 """ Adds another signer to already signed message @param cert - signer's certificate @param pkey - signer's private key @param digest_type - message digest to use as DigestType object (if None - default for key would be used) @param data - data to sign (if detached and Flags.REUSE_DIGEST is not specified) @param flags - ORed combination of Flags consants """

        if not pkey.cansign:
            raise ValueError("Specified keypair has no private part")
        if cert.pubkey != pkey:
            raise ValueError("Certificate doesn't match public key")
        if libcrypto.CMS_add1_signer(self.ptr, cert.cert, pkey.key,
                                          digest_type.digest, flags) is None:
            raise CMSError("adding signer")
        if flags & Flags.REUSE_DIGEST == 0:
            if data is not None:
                bio = Membio(data)
                biodata = bio.bio
            else:
                biodata = None
            res = libcrypto.CMS_final(self.ptr, biodata, None, flags)
            if res <= 0:
                raise CMSError("Cannot finalize CMS")