def guess_response(content_type, data, ssl2=False): """Guess which kind of message is in the record layer payload""" if content_type == ContentType.change_cipher_spec: if len(data) != 1: return "ChangeCipherSpec(invalid size)" return "ChangeCipherSpec()" elif content_type == ContentType.alert: if len(data) < 2: return "Alert(invalid size)" return "Alert({0}, {1})".format(AlertLevel.toStr(data[0]), AlertDescription.toStr(data[1])) elif content_type == ContentType.handshake: if not data: return "Handshake(invalid size)" if ssl2: return "Handshake({0})".format(SSL2HandshakeType.toStr(data[0])) else: return "Handshake({0})".format(HandshakeType.toStr(data[0])) elif content_type == ContentType.application_data: return "ApplicationData(len={0})".format(len(data)) else: return ("Message(content_type={0}, first_byte={1}, " "len={2})").format(ContentType.toStr(content_type), data[0], len(data))
def guess_response(content_type, data): """Guess which kind of message is in the record layer payload""" if content_type == ContentType.change_cipher_spec: if len(data) != 1: return "ChangeCipherSpec(invalid size)" return "ChangeCipherSpec()" elif content_type == ContentType.alert: if len(data) < 2: return "Alert(invalid size)" return "Alert({0}, {1})".format(AlertLevel.toStr(data[0]), AlertDescription.toStr(data[1])) elif content_type == ContentType.handshake: if not data: return "Handshake(invalid size)" return "Handshake({0})".format(HandshakeType.toStr(data[0])) elif content_type == ContentType.application_data: return "ApplicationData(len={0})".format(len(data)) else: return ("Message(content_type={0}, first_byte={1}, " "len={2})").format(ContentType.toStr(content_type), data[0], len(data))
def test_toRepr(self): self.assertEqual(AlertLevel.toStr(1), "warning")
def test_toRepr(self): self.assertEqual(AlertLevel.toStr(1), 'warning')