Example #1
0
    def _mac(self,
             unique_identifier=None,
             cryptographic_parameters=None,
             data=None,
             credential=None):
        operation = Operation(OperationEnum.MAC)

        req_pl = mac.MACRequestPayload(
            unique_identifier=attr.UniqueIdentifier(unique_identifier),
            cryptographic_parameters=cryptographic_parameters,
            data=objects.Data(data))
        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=req_pl)

        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
            payload_mac_data = None
        else:
            payload_unique_identifier = payload.unique_identifier
            payload_mac_data = payload.mac_data

        result = MACResult(batch_item.result_status, batch_item.result_reason,
                           batch_item.result_message,
                           payload_unique_identifier, payload_mac_data)
        return result
Example #2
0
    def test_read_valid(self):
        stream = self.encoding_full
        payload = mac.MACRequestPayload()
        payload.read(stream)

        self.assertEqual(self.unique_identifier, payload.unique_identifier)
        self.assertEqual(self.cryptographic_parameters,
                         payload.cryptographic_parameters)
        self.assertEqual(self.data, payload.data)
Example #3
0
    def test_write_valid(self):
        expected = self.encoding_full

        stream = utils.BytearrayStream()
        payload = mac.MACRequestPayload(self.unique_identifier,
                                        self.cryptographic_parameters,
                                        self.data)
        payload.write(stream)

        self.assertEqual(expected, stream)
Example #4
0
 def test_read_no_data(self):
     """
     Test that an InvalidKmipEncoding error gets raised when attempting to
     read a mac request encoding with no data.
     """
     payload = mac.MACRequestPayload()
     args = (self.encoding_no_data, )
     self.assertRaisesRegexp(exceptions.InvalidKmipEncoding,
                             "expected mac request data not found",
                             payload.read, *args)
Example #5
0
 def test_init_valid(self):
     """
     Test that the payload can be properly constructed and the attributes
     cab be properly set and retrieved.
     """
     payload = mac.MACRequestPayload(self.unique_identifier,
                                     self.cryptographic_parameters,
                                     self.data)
     self.assertEqual(payload.unique_identifier, self.unique_identifier)
     self.assertEqual(payload.cryptographic_parameters,
                      self.cryptographic_parameters)
     self.assertEqual(payload.data, self.data)
Example #6
0
 def test_write_with_no_data(self):
     """
     Test that an InvalidField error gets raised when attempting to
     write a mac request with no data.
     """
     stream = utils.BytearrayStream()
     payload = mac.MACRequestPayload(self.unique_identifier,
                                     self.cryptographic_parameters, None)
     args = (stream, )
     self.assertRaisesRegexp(exceptions.InvalidField,
                             "The mac request data is required",
                             payload.write, *args)
Example #7
0
 def _create_mac_payload(self):
     return mac.MACRequestPayload()
Example #8
0
 def test_init_with_none(self):
     mac.MACRequestPayload()