Verify ticket signature.

def verify_ticket_signature(self, data, sig):
        """Verify ticket signature. """
        try:
            signature = base64.b64decode(sig)
        except TypeError as e:
            if hasattr(self, "debug"):
                    print("Exception in function base64.b64decode. File %s" % (__file__))
                    print("%s" % e)
            return False
        if six.PY3:
            # To avoid "TypeError: Unicode-objects must be encoded before hashing'
            data = data.encode('utf-8')
        digest = hashlib.sha1(data).digest()
        if isinstance(self.pub_key, RSA.RSA_pub):
            try:
                self.pub_key.verify(digest, signature, 'sha1')
            except RSA.RSAError:
                return False
            return True
        if isinstance(self.pub_key, DSA.DSA_pub):
            try:
                return self.pub_key.verify_asn1(digest, signature)
            except DSA.DSAError as e:
                if hasattr(self, "debug"):
                    print("Exception in function self.pub_key.verify_asn1(digest, signature). File %s" % (__file__))
                    print("%s" % e)
                return False
        # Unknown key type
        return False