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
56 changes: 28 additions & 28 deletions kmip/pie/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ def create(self, algorithm, length, operation_policy_name=None, name=None,
key_attributes.extend(common_attributes)

if name:
key_attributes.extend(self._build_name_attribute(name))
key_attributes.extend(
[
self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
name
)
]
)

template = cobjects.TemplateAttribute(attributes=key_attributes)

Expand Down Expand Up @@ -320,39 +327,45 @@ def create_key_pair(self,

# Create public / private specific attributes
public_template = None
names = None
if public_name:
names = self._build_name_attribute(name=public_name)
attrs = []
if public_name:
attrs.append(
self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
public_name
)
)
if public_usage_mask:
attrs = [
attrs.append(
self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
public_usage_mask
)
]
if names or attrs:
)
if attrs:
public_template = cobjects.TemplateAttribute(
names=names,
attributes=attrs,
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)

private_template = None
names = None
if private_name:
names = self._build_name_attribute(name=private_name)
attrs = []
if private_name:
attrs.append(
self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
private_name
)
)
if private_usage_mask:
attrs = [
attrs.append(
self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
private_usage_mask
)
]
if names or attrs:
)
if attrs:
private_template = cobjects.TemplateAttribute(
names=names,
attributes=attrs,
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
Expand Down Expand Up @@ -1604,19 +1617,6 @@ def _build_common_attributes(self, operation_policy_name=None):

return common_attributes

def _build_name_attribute(self, name=None):
'''
Build a name attribute, returned in a list for ease
of use in the caller
'''
name_list = []
if name:
name_list.append(self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
name)
)
return name_list

def __enter__(self):
self.open()
return self
Expand Down
51 changes: 26 additions & 25 deletions kmip/tests/unit/pie/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,34 +573,35 @@ def test_create_key_pair_with_key_names(self):
specifically testing that the private / public names are correctly
sent with the request
"""
# Create the template to test the create key pair call
algorithm = enums.CryptographicAlgorithm.RSA
length = 2048
algorithm_attribute = self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, algorithm)
length_attribute = self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, length)

private_name_attribute = self.attribute_factory.create_attribute(
enums.AttributeType.NAME, "private")
public_name_attribute = self.attribute_factory.create_attribute(
enums.AttributeType.NAME, "public")

pair_attributes = [
algorithm_attribute,
length_attribute
]

template = obj.TemplateAttribute(
attributes=pair_attributes,
common_template = obj.TemplateAttribute(
attributes=[
self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
enums.CryptographicAlgorithm.RSA
),
self.attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
2048
)
],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
private_template = obj.TemplateAttribute(
names=[private_name_attribute],
attributes=[
self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
"Test_Private_Key"
)
],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
public_template = obj.TemplateAttribute(
names=[public_name_attribute],
attributes=[
self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
"Test_Public_Key"
)
],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)

Expand All @@ -617,12 +618,12 @@ def test_create_key_pair_with_key_names(self):
public_uid, private_uid = client.create_key_pair(
enums.CryptographicAlgorithm.RSA,
2048,
public_name="public",
private_name="private"
public_name="Test_Public_Key",
private_name="Test_Private_Key"
)

kwargs = {
"common_template_attribute": template,
"common_template_attribute": common_template,
"private_key_template_attribute": private_template,
"public_key_template_attribute": public_template
}
Expand Down