Example #1
0
 def pack(self, signature_a=True, signature_b=True) -> bytes:
     """
     Encode this block for transport.
     :param signature_a: False to pack EMPTY_SIG in the location of signature A, true to pack the signature A field.
     :param signature_b: False to pack EMPTY_SIG in the location of signature B, true to pack the signature B field.
     :return: the database_blob the data was packed into.
     """
     args = [self.sequence_number, self.public_key_a, self.public_key_b,
             self.signature_a if signature_a else EMPTY_SIGNATURE,
             self.signature_b if signature_b else EMPTY_SIGNATURE, self.amount, self.timestamp]
     return default_serializer.pack_serializable(BandwidthTransactionPayload(*args, 0))
    def test_version_response_payload(self):
        """
        Check if the version response is correctly serialized.
        """
        version = "v7.10.0"
        platform = "linux"

        version_response = VersionResponse(version, platform)
        serialized = default_serializer.pack_serializable(version_response)
        deserialized, _ = default_serializer.unpack_serializable(VersionResponse, serialized)

        self.assertEqual(version_response.version, version)
        self.assertEqual(version_response.platform, platform)
        self.assertEqual(deserialized.version, version)
        self.assertEqual(deserialized.platform, platform)
Example #3
0
    def __init__(self, metadata_type, reserved_flags, public_key, **kwargs):
        super().__init__()
        self.metadata_type = metadata_type
        self.reserved_flags = reserved_flags
        self.public_key = bytes(public_key)
        self.signature = bytes(
            kwargs["signature"]
        ) if "signature" in kwargs and kwargs["signature"] else None

        # Special case: free-for-all entries are allowed to go with zero key and without sig check
        if "unsigned" in kwargs and kwargs["unsigned"]:
            self.public_key = NULL_KEY
            self.signature = NULL_SIG
            return

        if "skip_key_check" in kwargs and kwargs["skip_key_check"]:
            return

        # This is integrity check for FFA payloads.
        if self.public_key == NULL_KEY:
            if self.signature == NULL_SIG:
                return
            raise InvalidSignatureException(
                "Tried to create FFA payload with non-null signature")

        serialized_data = default_serializer.pack_serializable(self)
        if "key" in kwargs and kwargs["key"]:
            key = kwargs["key"]
            if self.public_key != key.pub().key_to_bin()[10:]:
                raise KeysMismatchException(self.public_key,
                                            key.pub().key_to_bin()[10:])
            self.signature = default_eccrypto.create_signature(
                key, serialized_data)
        elif "signature" in kwargs:
            # This check ensures that an entry with a wrong signature will not proliferate further
            if not default_eccrypto.is_valid_signature(
                    default_eccrypto.key_from_public_bin(b"LibNaCLPK:" +
                                                         self.public_key),
                    serialized_data, self.signature):
                raise InvalidSignatureException(
                    "Tried to create payload with wrong signature")
        else:
            raise InvalidSignatureException(
                "Tried to create payload without signature")
Example #4
0
 def _serialized(self):
     serialized_data = default_serializer.pack_serializable(self)
     return serialized_data, self.signature
Example #5
0
 def serialize(self):
     return default_serializer.pack_serializable(self)
Example #6
0
 def fix_pack_torrents_checked(self, value):
     return b''.join(
         default_serializer.pack_serializable(TorrentInfoFormat(*sublist))
         for sublist in value)