Esempio n. 1
0
    def test_init_with_args(self):
        """
        Test that an Encrypt response payload can be constructed with valid
        values
        """
        payload = payloads.EncryptResponsePayload(
            unique_identifier='00000000-1111-2222-3333-444444444444',
            data=b'\x01\x02\x03',
            iv_counter_nonce=b'\x01'
        )

        self.assertEqual(
            '00000000-1111-2222-3333-444444444444',
            payload.unique_identifier
        )
        self.assertEqual(b'\x01\x02\x03', payload.data)
        self.assertEqual(b'\x01', payload.iv_counter_nonce)
Esempio n. 2
0
    def test_read(self):
        """
        Test that an Encrypt response payload can be read from a data stream.
        """
        payload = payloads.EncryptResponsePayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.data)
        self.assertEqual(None, payload.iv_counter_nonce)

        payload.read(self.full_encoding)

        self.assertEqual(
            'b4faee10-aa2a-4446-8ad4-0881f3422959',
            payload.unique_identifier
        )
        self.assertEqual(b'\x01\x23\x45\x67\x89\xAB\xCD\xEF', payload.data)
        self.assertEqual(b'\x01', payload.iv_counter_nonce)
Esempio n. 3
0
    def test_str(self):
        """
        Test that str can be applied to an Encrypt response payload
        """
        payload = payloads.EncryptResponsePayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            data=b'\x01\x23\x45\x67\x89\xAB\xCD\xEF',
            iv_counter_nonce=b'\x01'
        )

        expected = str({
            'unique_identifier': 'b4faee10-aa2a-4446-8ad4-0881f3422959',
            'data': b'\x01\x23\x45\x67\x89\xAB\xCD\xEF',
            'iv_counter_nonce': b'\x01'
        })
        observed = str(payload)

        self.assertEqual(expected, observed)
Esempio n. 4
0
    def test_repr(self):
        """
        Test that repr can be applied to an Encrypt response payload.
        """
        payload = payloads.EncryptResponsePayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            data=b'\x01\x23\x45\x67\x89\xAB\xCD\xEF',
            iv_counter_nonce=b'\x01'
        )
        expected = (
            "EncryptResponsePayload("
            "unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959', "
            "data=" + str(b'\x01\x23\x45\x67\x89\xAB\xCD\xEF') + ", "
            "iv_counter_nonce=" + str(b'\x01') + ")"
        )
        observed = repr(payload)

        self.assertEqual(expected, observed)
Esempio n. 5
0
    def test_read_partial(self):
        """
        Test that an Encrypt response payload can be read from a partial data
        stream containing the minimum required attributes.
        """
        payload = payloads.EncryptResponsePayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.data)
        self.assertEqual(None, payload.iv_counter_nonce)

        payload.read(self.minimum_encoding)

        self.assertEqual(
            'b4faee10-aa2a-4446-8ad4-0881f3422959',
            payload.unique_identifier
        )
        self.assertEqual(b'\x01\x02\x03\x04\x05\x06\x07\x08', payload.data)
        self.assertEqual(None, payload.iv_counter_nonce)
Esempio n. 6
0
 def _create_encrypt_payload(self):
     return payloads.EncryptResponsePayload()