Esempio n. 1
0
    def deserialize_with_header(cls,
                                header,
                                data,
                                decrypt_func,
                                sender_public_key: bytes = None,
                                **kwargs):
        sig = data[:cls.SIG_LEN]
        payload = data[cls.SIG_LEN:]

        if header.encrypted:
            try:
                payload = decrypt_func(payload)
            except exceptions.MessageError:
                raise
            except Exception as e:
                raise exceptions.DecryptionError(
                    "Unknown decryption problem") from e
        slots = serializer.loads(payload)

        instance = cls(
            header=header,
            sig=sig,
            slots=slots,
            deserialized=True,
            **kwargs,
        )

        if sender_public_key and cls.SIGN:
            instance.verify_signature(
                sender_public_key, msg_hash=instance.get_short_hash(payload))
        return instance
Esempio n. 2
0
 def equal_after_processing(self, o):
     s = serializer.dumps(o)
     o2 = serializer.loads(s)
     self.assertEqual(o, o2)
Esempio n. 3
0
 def test_disconnect_reason(self):
     r = message.Disconnect.REASON.TooManyPeers
     s = serializer.dumps(r)
     r2 = serializer.loads(s)
     self.assertIs(r, r2)