Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions kmip/core/messages/payloads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.

# Import payload base classes
from kmip.core.messages.payloads.base import (
RequestPayload,
ResponsePayload
)

# Import payload subclasses
from kmip.core.messages.payloads.activate import (
ActivateRequestPayload,
ActivateResponsePayload
Expand Down Expand Up @@ -176,6 +183,8 @@
"RekeyKeyPairResponsePayload",
"RekeyRequestPayload",
"RekeyResponsePayload",
"RequestPayload",
"ResponsePayload",
"RevokeRequestPayload",
"RevokeResponsePayload",
"SignRequestPayload",
Expand Down
14 changes: 5 additions & 9 deletions kmip/core/messages/payloads/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

from kmip.core import attributes
from kmip.core import enums

from kmip.core.primitives import Struct

from kmip.core.utils import BytearrayStream
from kmip.core.messages.payloads import base


class ActivateRequestPayload(Struct):
class ActivateRequestPayload(base.RequestPayload):
"""
A request payload for the Activate operation.

Expand All @@ -40,8 +38,7 @@ def __init__(self,
unique_identifier (UniqueIdentifier): The UUID of a managed
cryptographic object.
"""
super(ActivateRequestPayload, self).__init__(
tag=enums.Tags.REQUEST_PAYLOAD)
super(ActivateRequestPayload, self).__init__()
self.unique_identifier = unique_identifier
self.validate()

Expand Down Expand Up @@ -103,7 +100,7 @@ def validate(self):
raise TypeError(msg)


class ActivateResponsePayload(Struct):
class ActivateResponsePayload(base.ResponsePayload):
"""
A response payload for the Activate operation.

Expand All @@ -122,8 +119,7 @@ def __init__(self,
unique_identifier (UniqueIdentifier): The UUID of a managed
cryptographic object.
"""
super(ActivateResponsePayload, self).__init__(
tag=enums.Tags.RESPONSE_PAYLOAD)
super(ActivateResponsePayload, self).__init__()
if unique_identifier is None:
self.unique_identifier = attributes.UniqueIdentifier()
else:
Expand Down
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from kmip import enums
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class ArchiveRequestPayload(primitives.Struct):
class ArchiveRequestPayload(base.RequestPayload):
"""
A request payload for the Archive operation.

Expand All @@ -36,9 +37,7 @@ def __init__(self, unique_identifier=None):
unique_identifier (string): The ID of the managed object (e.g.,
a public key) to archive. Optional, defaults to None.
"""
super(ArchiveRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
super(ArchiveRequestPayload, self).__init__()

self._unique_identifier = None
self.unique_identifier = unique_identifier
Expand Down Expand Up @@ -151,7 +150,7 @@ def __str__(self):
})


class ArchiveResponsePayload(primitives.Struct):
class ArchiveResponsePayload(base.ResponsePayload):
"""
A response payload for the Archive operation.

Expand All @@ -167,9 +166,7 @@ def __init__(self, unique_identifier=None):
unique_identifier (string): The ID of the managed object (e.g.,
a public key) that was archived. Optional, defaults to None.
"""
super(ArchiveResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD
)
super(ArchiveResponsePayload, self).__init__()

self._unique_identifier = None
self.unique_identifier = unique_identifier
Expand Down
34 changes: 34 additions & 0 deletions kmip/core/messages/payloads/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2019 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from kmip.core import enums
from kmip.core import primitives


class RequestPayload(primitives.Struct):
"""
An abstract base class for KMIP request payloads.
"""
def __init__(self):
super(RequestPayload, self).__init__(enums.Tags.REQUEST_PAYLOAD)


class ResponsePayload(primitives.Struct):
"""
An abstract base class for KMIP response payloads.
"""

def __init__(self):
super(ResponsePayload, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from kmip import enums
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class CancelRequestPayload(primitives.Struct):
class CancelRequestPayload(base.RequestPayload):
"""
A request payload for the Cancel operation.

Expand All @@ -37,9 +38,7 @@ def __init__(self, asynchronous_correlation_value=None):
asynchronous_correlation_value (bytes): The ID of a pending
operation to cancel, in bytes. Optional, defaults to None.
"""
super(CancelRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
super(CancelRequestPayload, self).__init__()

self._asynchronous_correlation_value = None
self.asynchronous_correlation_value = asynchronous_correlation_value
Expand Down Expand Up @@ -159,7 +158,7 @@ def __str__(self):
})


class CancelResponsePayload(primitives.Struct):
class CancelResponsePayload(base.ResponsePayload):
"""
A response payload for the Cancel operation.

Expand All @@ -183,9 +182,7 @@ def __init__(self,
specifying the result of canceling the operation. Optional,
defaults to None.
"""
super(CancelResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD
)
super(CancelResponsePayload, self).__init__()

self._asynchronous_correlation_value = None
self._cancellation_result = None
Expand Down
9 changes: 5 additions & 4 deletions kmip/core/messages/payloads/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from kmip import enums
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class CheckRequestPayload(primitives.Struct):
class CheckRequestPayload(base.RequestPayload):
"""
A request payload for the Check operation.

Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(self,
lease should be available for on the checked object. Optional,
defaults to None.
"""
super(CheckRequestPayload, self).__init__(enums.Tags.REQUEST_PAYLOAD)
super(CheckRequestPayload, self).__init__()

self._unique_identifier = None
self._usage_limits_count = None
Expand Down Expand Up @@ -285,7 +286,7 @@ def __str__(self):
})


class CheckResponsePayload(primitives.Struct):
class CheckResponsePayload(base.ResponsePayload):
"""
A response payload for the Check operation.

Expand Down Expand Up @@ -320,7 +321,7 @@ def __init__(self,
lease should be available for on the checked object. Optional,
defaults to None.
"""
super(CheckResponsePayload, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
super(CheckResponsePayload, self).__init__()

self._unique_identifier = None
self._usage_limits_count = None
Expand Down
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from kmip.core import objects
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class CreateRequestPayload(primitives.Struct):
class CreateRequestPayload(base.RequestPayload):
"""
A request payload for the Create operation.

Expand Down Expand Up @@ -52,9 +53,7 @@ def __init__(self,
structure containing the storage masks permissible for the new
object. Added in KMIP 2.0. Optional, defaults to None.
"""
super(CreateRequestPayload, self).__init__(
tag=enums.Tags.REQUEST_PAYLOAD
)
super(CreateRequestPayload, self).__init__()

self._object_type = None
self._template_attribute = None
Expand Down Expand Up @@ -316,7 +315,7 @@ def __str__(self):
return '{' + value + '}'


class CreateResponsePayload(primitives.Struct):
class CreateResponsePayload(base.ResponsePayload):
"""
A response payload for the Create operation.

Expand Down Expand Up @@ -344,9 +343,7 @@ def __init__(self,
structure containing a set of attributes that were set on the
new object. Optional, defaults to None.
"""
super(CreateResponsePayload, self).__init__(
tag=enums.Tags.RESPONSE_PAYLOAD
)
super(CreateResponsePayload, self).__init__()

self._object_type = None
self._unique_identifier = None
Expand Down
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/create_key_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from kmip.core import objects
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class CreateKeyPairRequestPayload(primitives.Struct):
class CreateKeyPairRequestPayload(base.RequestPayload):
"""
A request payload for the CreateKeyPair operation.

Expand Down Expand Up @@ -80,9 +81,7 @@ def __init__(self,
permissible for the new public key. Added in KMIP 2.0.
Optional, defaults to None.
"""
super(CreateKeyPairRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
super(CreateKeyPairRequestPayload, self).__init__()

self._common_template_attribute = None
self._private_key_template_attribute = None
Expand Down Expand Up @@ -518,7 +517,7 @@ def __str__(self):
return '{' + value + '}'


class CreateKeyPairResponsePayload(primitives.Struct):
class CreateKeyPairResponsePayload(base.ResponsePayload):
"""
A response payload for the CreateKeyPair operation.

Expand Down Expand Up @@ -556,9 +555,7 @@ def __init__(self,
tag containing the set of attributes that were set on the new
public key. Optional, defaults to None.
"""
super(CreateKeyPairResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD
)
super(CreateKeyPairResponsePayload, self).__init__()

self._private_key_unique_identifier = None
self._public_key_unique_identifier = None
Expand Down
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from kmip.core import enums
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class DecryptRequestPayload(primitives.Struct):
class DecryptRequestPayload(base.RequestPayload):
"""
A request payload for the Decrypt operation.

Expand Down Expand Up @@ -74,9 +75,7 @@ def __init__(self,
authenticated encryption cipher. Optional, defaults to None.
Added in KMIP 1.4.
"""
super(DecryptRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
super(DecryptRequestPayload, self).__init__()

self._unique_identifier = None
self._cryptographic_parameters = None
Expand Down Expand Up @@ -394,7 +393,7 @@ def __str__(self):
})


class DecryptResponsePayload(primitives.Struct):
class DecryptResponsePayload(base.ResponsePayload):
"""
A response payload for the Decrypt operation.

Expand All @@ -417,9 +416,7 @@ def __init__(self,
data (bytes): The decrypted data in binary form. Required for
encoding and decoding.
"""
super(DecryptResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD
)
super(DecryptResponsePayload, self).__init__()

self._unique_identifier = None
self._data = None
Expand Down
13 changes: 5 additions & 8 deletions kmip/core/messages/payloads/delete_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from kmip.core import objects
from kmip.core import primitives
from kmip.core import utils
from kmip.core.messages.payloads import base


class DeleteAttributeRequestPayload(primitives.Struct):
class DeleteAttributeRequestPayload(base.RequestPayload):
"""
A request payload for the DeleteAttribute operation.

Expand Down Expand Up @@ -65,9 +66,7 @@ def __init__(self,
KMIP 2.0+. Optional, defaults to None. Must be specified if the
current attribute is not specified.
"""
super(DeleteAttributeRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
super(DeleteAttributeRequestPayload, self).__init__()

self._unique_identifier = None
self._attribute_name = None
Expand Down Expand Up @@ -374,7 +373,7 @@ def __ne__(self, other):
return NotImplemented


class DeleteAttributeResponsePayload(primitives.Struct):
class DeleteAttributeResponsePayload(base.ResponsePayload):
"""
A response payload for the DeleteAttribute operation.

Expand All @@ -397,9 +396,7 @@ def __init__(self, unique_identifier=None, attribute=None):
that was deleted. Used in KMIP 1.0 - 1.4. Defaults to None.
Required for read/write.
"""
super(DeleteAttributeResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD
)
super(DeleteAttributeResponsePayload, self).__init__()

self._unique_identifier = None
self._attribute = None
Expand Down
Loading