def verify(self, msg, sig, key):
        """
        Verify a message signature

        :param msg: The message
        :param sig: A signature
        :param key: A ec.EllipticCurvePublicKey to use for the verification.
        :raises: BadSignature if the signature can't be verified.
        :return: True
        """
        if not isinstance(key, ec.EllipticCurvePublicKey):
            raise TypeError(
                "The public key must be an instance of "
                "ec.EllipticCurvePublicKey")
        self._cross_check(key)

        num_bits = key.curve.key_size
        num_bytes = (num_bits + 7) // 8
        if len(sig) != 2 * num_bytes:
            raise ValueError('Invalid signature')

        try:
            # cryptography uses ASN.1-encoded signature data; split JWS
            # signature (r||s) and encode before verification
            (r, s) = self._split_raw_signature(sig)
            asn1sig = encode_dss_signature(r, s)
            key.verify(asn1sig, msg, ec.ECDSA(self.hash_algorithm()))
        except InvalidSignature as err:
            raise BadSignature(err)
        else:
            return True
Verify a message signature

        :param msg: The message
        :param sig: A signature
        :param key: A ec.EllipticCurvePublicKey to use for the verification.
        :raises: BadSignature if the signature can't be verified.
        :return: True