_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q270500 | Boolean.write | test | def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
Boolean object. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
| python | {
"resource": ""
} |
q270501 | Boolean.validate | test | def validate(self):
"""
Verify that the value of the Boolean object is valid.
Raises:
TypeError: if the value is not of type bool.
"""
if self.value:
| python | {
"resource": ""
} |
q270502 | Interval.read | test | def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the Interval from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of an Interval. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the Interval encoding read in has an
| python | {
"resource": ""
} |
q270503 | Interval.validate | test | def validate(self):
"""
Verify that the value of the Interval is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by an unsigned
32-bit integer
"""
if self.value is not None:
if type(self.value) not in six.integer_types:
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
else:
| python | {
"resource": ""
} |
q270504 | Key.key_wrapping_data | test | def key_wrapping_data(self):
"""
Retrieve all of the relevant key wrapping data fields and return them
as a dictionary.
"""
key_wrapping_data = {}
encryption_key_info = {
'unique_identifier': self._kdw_eki_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_eki_cp_block_cipher_mode,
'padding_method': self._kdw_eki_cp_padding_method,
'hashing_algorithm': self._kdw_eki_cp_hashing_algorithm,
'key_role_type': self._kdw_eki_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_eki_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_eki_cp_cryptographic_algorithm,
'random_iv': self._kdw_eki_cp_random_iv,
'iv_length': self._kdw_eki_cp_iv_length,
'tag_length': self._kdw_eki_cp_tag_length,
'fixed_field_length': self._kdw_eki_cp_fixed_field_length,
'invocation_field_length':
self._kdw_eki_cp_invocation_field_length,
'counter_length': self._kdw_eki_cp_counter_length,
'initial_counter_value':
self._kdw_eki_cp_initial_counter_value
}
}
if not any(encryption_key_info['cryptographic_parameters'].values()):
encryption_key_info['cryptographic_parameters'] = {}
if not any(encryption_key_info.values()):
encryption_key_info = {}
mac_sign_key_info = {
'unique_identifier': self._kdw_mski_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_mski_cp_block_cipher_mode,
'padding_method': self._kdw_mski_cp_padding_method,
'hashing_algorithm': self._kdw_mski_cp_hashing_algorithm,
'key_role_type': self._kdw_mski_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_mski_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_mski_cp_cryptographic_algorithm,
'random_iv': self._kdw_mski_cp_random_iv,
'iv_length': self._kdw_mski_cp_iv_length,
'tag_length': self._kdw_mski_cp_tag_length,
| python | {
"resource": ""
} |
q270505 | Key.key_wrapping_data | test | def key_wrapping_data(self, value):
"""
Set the key wrapping data attributes using a dictionary.
"""
if value is None:
value = {}
elif not isinstance(value, dict):
raise TypeError("Key wrapping data must be a dictionary.")
self._kdw_wrapping_method = value.get('wrapping_method')
eki = value.get('encryption_key_information')
if eki is None:
eki = {}
self._kdw_eki_unique_identifier = eki.get('unique_identifier')
eki_cp = eki.get('cryptographic_parameters')
if eki_cp is None:
eki_cp = {}
self._kdw_eki_cp_block_cipher_mode = eki_cp.get('block_cipher_mode')
self._kdw_eki_cp_padding_method = eki_cp.get('padding_method')
self._kdw_eki_cp_hashing_algorithm = eki_cp.get('hashing_algorithm')
self._kdw_eki_cp_key_role_type = eki_cp.get('key_role_type')
self._kdw_eki_cp_digital_signature_algorithm = \
eki_cp.get('digital_signature_algorithm')
self._kdw_eki_cp_cryptographic_algorithm = \
eki_cp.get('cryptographic_algorithm')
self._kdw_eki_cp_random_iv = eki_cp.get('random_iv')
self._kdw_eki_cp_iv_length = eki_cp.get('iv_length')
self._kdw_eki_cp_tag_length = eki_cp.get('tag_length')
self._kdw_eki_cp_fixed_field_length = eki_cp.get('fixed_field_length')
self._kdw_eki_cp_invocation_field_length = \
eki_cp.get('invocation_field_length')
self._kdw_eki_cp_counter_length = eki_cp.get('counter_length')
self._kdw_eki_cp_initial_counter_value = \
eki_cp.get('initial_counter_value')
mski = value.get('mac_signature_key_information')
if mski is None:
mski = {}
self._kdw_mski_unique_identifier = mski.get('unique_identifier')
mski_cp = mski.get('cryptographic_parameters')
if mski_cp is None:
| python | {
"resource": ""
} |
q270506 | PublicKey.validate | test | def validate(self):
"""
Verify that the contents of the PublicKey object are valid.
Raises:
TypeError: if the types of any PublicKey attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("key value must be bytes")
elif not isinstance(self.cryptographic_algorithm,
enums.CryptographicAlgorithm):
raise TypeError("key algorithm must be a CryptographicAlgorithm "
"enumeration")
elif not isinstance(self.cryptographic_length, six.integer_types):
raise TypeError("key length must be an integer")
elif not isinstance(self.key_format_type, enums.KeyFormatType):
raise TypeError("key format type must be a KeyFormatType "
"enumeration")
elif self.key_format_type not in self._valid_formats:
raise ValueError("key format type must be one of {0}".format(
self._valid_formats))
# TODO (peter-hamilton) Verify that the key bytes match the key format
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count): | python | {
"resource": ""
} |
q270507 | SecretData.validate | test | def validate(self):
"""
Verify that the contents of the SecretData object are valid.
Raises:
TypeError: if the types of any SecretData attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("secret value must be bytes")
elif not isinstance(self.data_type, enums.SecretDataType):
raise TypeError("secret data type must be a SecretDataType "
"enumeration")
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count):
mask = self.cryptographic_usage_masks[i]
if not isinstance(mask, enums.CryptographicUsageMask):
position = "({0} in list)".format(i)
| python | {
"resource": ""
} |
q270508 | OpaqueObject.validate | test | def validate(self):
"""
Verify that the contents of the OpaqueObject are valid.
Raises:
TypeError: if the types of any OpaqueObject attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("opaque value must be bytes")
elif not isinstance(self.opaque_type, enums.OpaqueDataType):
raise TypeError("opaque data type must be an OpaqueDataType "
"enumeration")
name_count = len(self.names)
for i | python | {
"resource": ""
} |
q270509 | convert_attribute_name_to_tag | test | def convert_attribute_name_to_tag(value):
"""
A utility function that converts an attribute name string into the
corresponding attribute tag.
For example: 'State' -> enums.Tags.STATE
Args:
value (string): The string name of the attribute.
Returns:
enum: The Tags enumeration value that corresponds to the attribute
name string.
Raises:
ValueError: if the attribute name string is not a string or if it is
an unrecognized attribute name
"""
if not | python | {
"resource": ""
} |
q270510 | convert_attribute_tag_to_name | test | def convert_attribute_tag_to_name(value):
"""
A utility function that converts an attribute tag into the corresponding
attribute name string.
For example: enums.Tags.STATE -> 'State'
Args:
value (enum): The Tags enumeration value of the attribute.
Returns:
string: The attribute name string that corresponds to the attribute
tag.
Raises:
ValueError: if the attribute tag is not a Tags enumeration or if it
is unrecognized attribute tag
"""
if not | python | {
"resource": ""
} |
q270511 | get_bit_mask_from_enumerations | test | def get_bit_mask_from_enumerations(enumerations):
"""
A utility function that computes a bit mask from a collection of
enumeration values.
Args:
enumerations (list): A list of enumeration values to be combined in a
composite bit mask.
Returns:
| python | {
"resource": ""
} |
q270512 | get_enumerations_from_bit_mask | test | def get_enumerations_from_bit_mask(enumeration, mask):
"""
A utility function that creates a list of enumeration values from a bit
mask for a specific mask enumeration class.
Args:
enumeration (class): The enumeration class from which to draw
enumeration values.
mask (int): The bit mask from | python | {
"resource": ""
} |
q270513 | is_bit_mask | test | def is_bit_mask(enumeration, potential_mask):
"""
A utility function that checks if the provided value is a composite bit
mask of enumeration values in the specified enumeration class.
Args:
enumeration (class): One of the mask enumeration classes found in this
file. These include:
* Cryptographic Usage Mask
* Protection Storage Mask
* Storage Status Mask
potential_mask (int): A potential bit mask composed of enumeration
values belonging to the enumeration class.
Returns:
True: if the potential mask is a valid bit mask of the mask enumeration
False: otherwise
"""
if | python | {
"resource": ""
} |
q270514 | CreateKeyPairRequestPayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(CreateKeyPairRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.COMMON_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._common_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
self._common_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(enums.Tags.COMMON_ATTRIBUTES, local_buffer):
attributes = objects.Attributes(
tag=enums.Tags.COMMON_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._common_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
| python | {
"resource": ""
} |
q270515 | CreateKeyPairRequestPayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._common_template_attribute is not None:
self._common_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._common_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._common_template_attribute
| python | {
"resource": ""
} |
q270516 | CreateKeyPairResponsePayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the private key unique identifier or
the public key unique identifier is missing from the encoded
payload.
"""
super(CreateKeyPairResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._private_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER
)
self._private_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"private key unique identifier."
)
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._public_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER
)
self._public_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
| python | {
"resource": ""
} |
q270517 | CreateKeyPairResponsePayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the private key unique identifier or the
public key unique identifier is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._private_key_unique_identifier:
self._private_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the private "
"key unique identifier field."
)
if self._public_key_unique_identifier:
self._public_key_unique_identifier.write(
| python | {
"resource": ""
} |
q270518 | GetAttributeListRequestPayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList request payload and decode
it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(GetAttributeListRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
| python | {
"resource": ""
} |
q270519 | GetAttributeListRequestPayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList request payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
| python | {
"resource": ""
} |
q270520 | GetAttributeListResponsePayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList response payload and
decode it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the unique identifier or attribute
names are missing from the encoded payload.
"""
super(GetAttributeListResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is missing "
"the unique identifier."
)
names = list()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer):
name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME)
name.read(local_buffer, kmip_version=kmip_version)
names.append(name)
if len(names) == 0:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is "
"missing the attribute names."
)
self._attribute_names = names
else:
while self.is_tag_next(
enums.Tags.ATTRIBUTE_REFERENCE,
local_buffer
| python | {
"resource": ""
} |
q270521 | GetAttributeListResponsePayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList response payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the unique identifier or attribute name
are not defined.
"""
local_buffer = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The GetAttributeList response payload is missing the unique "
"identifier field."
)
if self._attribute_names:
if kmip_version < enums.KMIPVersion.KMIP_2_0:
for attribute_name in self._attribute_names:
attribute_name.write(
local_buffer,
kmip_version=kmip_version
)
else:
# NOTE (ph) This approach simplifies backwards compatible
# issues but limits easy support for Attribute
# Reference structures going forward, specifically
# limiting the use of VendorIdentification for
# custom attributes. If custom attributes need to
| python | {
"resource": ""
} |
q270522 | get_json_files | test | def get_json_files(p):
"""
Scan the provided policy directory for all JSON policy | python | {
"resource": ""
} |
q270523 | PolicyDirectoryMonitor.scan_policies | test | def scan_policies(self):
"""
Scan the policy directory for policy data.
"""
policy_files = get_json_files(self.policy_directory)
for f in set(policy_files) - set(self.policy_files):
self.file_timestamps[f] = 0
for f in set(self.policy_files) - set(policy_files):
self.logger.info("Removing policies for file: {}".format(f))
self.file_timestamps.pop(f, None)
for p in self.policy_cache.keys():
self.disassociate_policy_and_file(p, f)
for p in [k for k, v in self.policy_map.items() if v == f]:
self.restore_or_delete_policy(p)
self.policy_files = policy_files
for f in sorted(self.file_timestamps.keys()):
t = os.path.getmtime(f)
if t > self.file_timestamps[f]:
self.logger.info("Loading policies for file: {}".format(f))
self.file_timestamps[f] = t
old_p = [k for k, v in self.policy_map.items() if v == f]
try:
new_p = operation_policy.read_policy_from_file(f)
except ValueError:
self.logger.error("Failure loading file: {}".format(f))
self.logger.debug("", exc_info=True)
continue
for p in new_p.keys():
self.logger.info("Loading policy: {}".format(p))
if p in self.reserved_policies:
self.logger.warning(
"Policy '{}' overwrites a reserved policy and "
"will be thrown out.".format(p)
)
| python | {
"resource": ""
} |
q270524 | PolicyDirectoryMonitor.run | test | def run(self):
"""
Start monitoring operation policy files.
"""
self.initialize_tracking_structures()
if self.live_monitoring:
self.logger.info("Starting up the operation policy file monitor.")
while not self.halt_trigger.is_set():
| python | {
"resource": ""
} |
q270525 | get_certificate_from_connection | test | def get_certificate_from_connection(connection):
"""
Extract an X.509 certificate from a socket connection.
"""
certificate = | python | {
"resource": ""
} |
q270526 | get_extended_key_usage_from_certificate | test | def get_extended_key_usage_from_certificate(certificate):
"""
Given an X.509 certificate, extract and return the extendedKeyUsage
extension.
| python | {
"resource": ""
} |
q270527 | get_common_names_from_certificate | test | def get_common_names_from_certificate(certificate):
"""
Given an X.509 certificate, extract and return all common names.
"""
common_names = certificate.subject.get_attributes_for_oid(
| python | {
"resource": ""
} |
q270528 | get_client_identity_from_certificate | test | def get_client_identity_from_certificate(certificate):
"""
Given an X.509 certificate, extract and return the client identity.
"""
client_ids = get_common_names_from_certificate(certificate)
if len(client_ids) > 0:
| python | {
"resource": ""
} |
q270529 | CreateRequestPayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Create request payload and decode it into
its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the object type or template
attribute is missing from the encoded payload.
"""
super(CreateRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer):
self._object_type = primitives.Enumeration(
enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
)
self._object_type.read(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidKmipEncoding(
"The Create request payload encoding is missing the object "
"type."
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer):
self._template_attribute = objects.TemplateAttribute()
self._template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The Create request payload encoding is missing the "
"template attribute."
)
else:
| python | {
"resource": ""
} |
q270530 | CreateRequestPayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Create request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the object type attribute or template
attribute is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._object_type:
self._object_type.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The Create request payload is missing the object type field."
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._template_attribute:
self._template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The Create request payload is missing the template "
"attribute field."
)
else:
# NOTE (ph) For now, leave attributes natively in TemplateAttribute
# form and just convert to the KMIP 2.0 Attributes form as needed
# for encoding/decoding purposes. Changing the payload to require
# the new Attributes structure will trigger a bunch of second-order
# effects across the client | python | {
"resource": ""
} |
q270531 | CreateResponsePayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Create response payload and decode it into
its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the object type or unique
identifier is missing from the encoded payload.
"""
super(CreateResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer):
self._object_type = primitives.Enumeration(
enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
)
self._object_type.read(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidKmipEncoding(
"The Create response payload encoding is missing the object "
"type."
| python | {
"resource": ""
} |
q270532 | CreateResponsePayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Create response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the object type attribute or unique
identifier is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._object_type:
self._object_type.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The Create response payload is missing the object type field."
)
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
| python | {
"resource": ""
} |
q270533 | ObjectFactory.convert | test | def convert(self, obj):
"""
Convert a Pie object into a core secret object and vice versa.
Args:
obj (various): A Pie or core secret object to convert into the
opposite object space. Required.
Raises:
TypeError: if the object type is unrecognized or unsupported.
"""
if isinstance(obj, pobjects.SymmetricKey):
return self._build_core_key(obj, secrets.SymmetricKey)
elif isinstance(obj, secrets.SymmetricKey):
return self._build_pie_key(obj, pobjects.SymmetricKey)
elif isinstance(obj, pobjects.PublicKey):
return self._build_core_key(obj, secrets.PublicKey)
elif isinstance(obj, secrets.PublicKey):
return self._build_pie_key(obj, pobjects.PublicKey)
elif isinstance(obj, pobjects.PrivateKey):
return self._build_core_key(obj, secrets.PrivateKey)
elif isinstance(obj, secrets.PrivateKey):
return self._build_pie_key(obj, pobjects.PrivateKey)
| python | {
"resource": ""
} |
q270534 | EncryptResponsePayload.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Encrypt response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the unique_identifier or data attributes
are missing from the encoded payload.
"""
super(EncryptResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
else: | python | {
"resource": ""
} |
q270535 | DeriveKeyRequestPayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the DeriveKey request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(DeriveKeyRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer):
self._object_type = primitives.Enumeration(
enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
)
self._object_type.read(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidKmipEncoding(
"The DeriveKey request payload encoding is missing the object "
"type."
)
unique_identifiers = []
while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
unique_identifier.read(local_buffer, kmip_version=kmip_version)
unique_identifiers.append(unique_identifier)
if not unique_identifiers:
raise exceptions.InvalidKmipEncoding(
"The DeriveKey request payload encoding is missing the unique "
"identifiers."
)
else:
self._unique_identifiers = unique_identifiers
if self.is_tag_next(enums.Tags.DERIVATION_METHOD, local_buffer):
self._derivation_method = primitives.Enumeration(
enums.DerivationMethod,
tag=enums.Tags.DERIVATION_METHOD
)
self._derivation_method.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The DeriveKey request payload encoding is missing the "
| python | {
"resource": ""
} |
q270536 | DeriveKeyRequestPayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the DeriveKey request payload to a stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._object_type:
self._object_type.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The DeriveKey request payload is missing the object type "
"field."
)
if self._unique_identifiers:
for unique_identifier in self._unique_identifiers:
unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The DeriveKey request payload is missing the unique "
"identifiers field."
)
if self._derivation_method:
self._derivation_method.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The DeriveKey request payload is missing the derivation "
"method field."
)
if self._derivation_parameters:
self._derivation_parameters.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
| python | {
"resource": ""
} |
q270537 | AttributePolicy.is_attribute_supported | test | def is_attribute_supported(self, attribute):
"""
Check if the attribute is supported by the current KMIP version.
Args:
attribute (string): The name of the attribute
(e.g., 'Cryptographic Algorithm'). Required.
Returns: | python | {
"resource": ""
} |
q270538 | AttributePolicy.is_attribute_deprecated | test | def is_attribute_deprecated(self, attribute):
"""
Check if the attribute is deprecated by the current KMIP version.
Args:
attribute (string): The name of the attribute
(e.g., 'Unique Identifier'). Required.
"""
rule_set = self._attribute_rule_sets.get(attribute)
if rule_set.version_deprecated: | python | {
"resource": ""
} |
q270539 | AttributePolicy.is_attribute_applicable_to_object_type | test | def is_attribute_applicable_to_object_type(self, attribute, object_type):
"""
Check if the attribute is supported by the given object type.
Args:
attribute (string): The name of the attribute (e.g., 'Name').
Required.
object_type (ObjectType): An ObjectType enumeration
(e.g., ObjectType.SYMMETRIC_KEY). Required.
Returns:
bool: True if the attribute is applicable to the object type.
False otherwise.
| python | {
"resource": ""
} |
q270540 | AttributePolicy.is_attribute_multivalued | test | def is_attribute_multivalued(self, attribute):
"""
Check if the attribute is allowed to have multiple instances.
Args:
attribute (string): The name of the attribute
(e.g., 'State'). Required.
"""
| python | {
"resource": ""
} |
q270541 | ConfigHelper.get_valid_value | test | def get_valid_value(self, direct_value, config_section,
config_option_name, default_value):
"""Returns a value that can be used as a parameter in client or
server. If a direct_value is given, that value will be returned
instead of the value from the config file. If the appropriate config
file option is not found, the default_value is returned.
:param direct_value: represents a direct value that should be used.
supercedes values from config files
:param config_section: which section of the config file to use
:param config_option_name: name of config option value
:param default_value: default value to be used if other options not
found
:returns: a value that can be used as a parameter
"""
ARG_MSG = "Using given value '{0}' for {1}"
CONF_MSG = "Using value '{0}' from configuration file {1} for {2}"
DEFAULT_MSG = "Using default value '{0}' for {1}"
if direct_value:
return_value = direct_value
self.logger.debug(ARG_MSG.format(direct_value, config_option_name))
else:
try:
| python | {
"resource": ""
} |
q270542 | CheckResponsePayload.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Check response payload and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(CheckResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream):
self._usage_limits_count = primitives.LongInteger(
| python | {
"resource": ""
} |
q270543 | CheckResponsePayload.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Check response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._usage_limits_count:
self._usage_limits_count.write(
local_stream,
kmip_version=kmip_version
| python | {
"resource": ""
} |
q270544 | AttributeReference.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Read the data stream and decode the AttributeReference structure into
its parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidKmipEncoding: Raised if the vendor identification or
attribute name is missing from the encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the AttributeReference structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the AttributeReference "
| python | {
"resource": ""
} |
q270545 | AttributeReference.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Write the AttributeReference structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
Attributes structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the vendor identification or attribute name
fields are not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the AttributeReference structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the AttributeReference "
"object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
if self._vendor_identification:
| python | {
"resource": ""
} |
q270546 | Attributes.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Read the data stream and decode the Attributes structure into its
parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
AttributeNotSupported: Raised if an unsupported attribute is
encountered while decoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the Attributes object.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the Attributes object.".format(
kmip_version.value
)
)
super(Attributes, self).read(input_stream, kmip_version=kmip_version)
local_stream = BytearrayStream(input_stream.read(self.length))
while True:
if len(local_stream) < 3:
| python | {
"resource": ""
} |
q270547 | Attributes.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Write the Attributes structure encoding to the data stream.
Args:
output_stream (stream): A data stream in which to encode
Attributes structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
AttributeNotSupported: Raised if an unsupported attribute is
found in the attribute list while encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the Attributes object.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the Attributes object.".format(
kmip_version.value
)
)
| python | {
"resource": ""
} |
q270548 | Nonce.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Nonce struct and decode it into its
constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the nonce ID or nonce value is missing from
| python | {
"resource": ""
} |
q270549 | Nonce.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Nonce struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the nonce ID or nonce value is not defined.
"""
local_stream = BytearrayStream()
| python | {
"resource": ""
} |
q270550 | UsernamePasswordCredential.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the UsernamePasswordCredential struct and
decode it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the username is missing from the encoding. | python | {
"resource": ""
} |
q270551 | UsernamePasswordCredential.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the UsernamePasswordCredential struct to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
| python | {
"resource": ""
} |
q270552 | DeviceCredential.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the DeviceCredential struct and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(DeviceCredential, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.DEVICE_SERIAL_NUMBER, local_stream):
self._device_serial_number = primitives.TextString(
tag=enums.Tags.DEVICE_SERIAL_NUMBER
)
self._device_serial_number.read(
local_stream,
kmip_version=kmip_version
)
| python | {
"resource": ""
} |
q270553 | DeviceCredential.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the DeviceCredential struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._device_serial_number is not None:
self._device_serial_number.write(
local_stream,
kmip_version=kmip_version
)
if self._password is not None:
self._password.write(
local_stream,
kmip_version=kmip_version
)
if self._device_identifier is not None:
self._device_identifier.write(
local_stream,
kmip_version=kmip_version | python | {
"resource": ""
} |
q270554 | Credential.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Credential struct and decode it into its
constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if either the credential type or value are
missing from the encoding.
"""
super(Credential, self).read(input_stream, kmip_version=kmip_version)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.CREDENTIAL_TYPE, local_stream):
self._credential_type = primitives.Enumeration(
enum=enums.CredentialType,
tag=enums.Tags.CREDENTIAL_TYPE
)
self._credential_type.read(local_stream, kmip_version=kmip_version)
else:
raise ValueError(
"Credential encoding missing the credential type."
)
if self.is_tag_next(enums.Tags.CREDENTIAL_VALUE, local_stream): | python | {
"resource": ""
} |
q270555 | Credential.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Credential struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if either the credential type or value are not
defined.
"""
local_stream = BytearrayStream()
if self._credential_type:
self._credential_type.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
| python | {
"resource": ""
} |
q270556 | MACSignatureKeyInformation.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the MACSignatureKeyInformation struct and
decode it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(MACSignatureKeyInformation, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
| python | {
"resource": ""
} |
q270557 | MACSignatureKeyInformation.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the MACSignatureKeyInformation struct to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Invalid struct missing the unique identifier | python | {
"resource": ""
} |
q270558 | KeyWrappingData.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the KeyWrappingData struct and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(KeyWrappingData, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream):
self._wrapping_method = primitives.Enumeration(
enum=enums.WrappingMethod,
tag=enums.Tags.WRAPPING_METHOD
)
self._wrapping_method.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Invalid struct missing the wrapping method attribute."
)
if self.is_tag_next(
enums.Tags.ENCRYPTION_KEY_INFORMATION,
local_stream
):
self._encryption_key_information = EncryptionKeyInformation()
self._encryption_key_information.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.MAC_SIGNATURE_KEY_INFORMATION,
local_stream
):
self._mac_signature_key_information = MACSignatureKeyInformation()
self._mac_signature_key_information.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.MAC_SIGNATURE, local_stream):
| python | {
"resource": ""
} |
q270559 | KeyWrappingData.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the KeyWrappingData struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._wrapping_method:
self._wrapping_method.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Invalid struct missing the wrapping method attribute."
)
if self._encryption_key_information:
self._encryption_key_information.write(
local_stream,
kmip_version=kmip_version
)
if self._mac_signature_key_information:
self._mac_signature_key_information.write(
| python | {
"resource": ""
} |
q270560 | KeyWrappingSpecification.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the KeyWrappingSpecification struct and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(KeyWrappingSpecification, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream):
self._wrapping_method = primitives.Enumeration(
enum=enums.WrappingMethod,
tag=enums.Tags.WRAPPING_METHOD
)
self._wrapping_method.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Invalid struct missing the wrapping method attribute."
)
if self.is_tag_next(
enums.Tags.ENCRYPTION_KEY_INFORMATION,
local_stream
):
self._encryption_key_information = EncryptionKeyInformation()
self._encryption_key_information.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.MAC_SIGNATURE_KEY_INFORMATION,
local_stream
):
self._mac_signature_key_information = MACSignatureKeyInformation()
self._mac_signature_key_information.read(
| python | {
"resource": ""
} |
q270561 | KeyWrappingSpecification.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the KeyWrappingSpecification struct to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._wrapping_method:
self._wrapping_method.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Invalid struct missing the wrapping method attribute."
)
if self._encryption_key_information:
self._encryption_key_information.write(
local_stream,
kmip_version=kmip_version
)
| python | {
"resource": ""
} |
q270562 | ExtensionInformation.read | test | def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the ExtensionInformation object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(ExtensionInformation, self).read(
istream,
kmip_version=kmip_version
| python | {
"resource": ""
} |
q270563 | ExtensionInformation.write | test | def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the ExtensionInformation object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
self.extension_name.write(tstream, kmip_version=kmip_version)
if self.extension_tag is not None:
| python | {
"resource": ""
} |
q270564 | ExtensionInformation.create | test | def create(cls, extension_name=None, extension_tag=None,
extension_type=None):
"""
Construct an ExtensionInformation object from provided extension
values.
Args:
extension_name (str): The name of the extension. Optional,
defaults to None.
extension_tag (int): The tag number of the extension. Optional,
defaults to None.
extension_type (int): The type index of the extension. Optional,
defaults to None.
| python | {
"resource": ""
} |
q270565 | RevocationReason.read | test | def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the RevocationReason object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(RevocationReason, self).read(istream, kmip_version=kmip_version)
| python | {
"resource": ""
} |
q270566 | RevocationReason.write | test | def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the RevocationReason object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
| python | {
"resource": ""
} |
q270567 | RevocationReason.validate | test | def validate(self):
"""
validate the RevocationReason object
"""
if not isinstance(self.revocation_code, RevocationReasonCode):
msg = "RevocationReaonCode expected"
raise TypeError(msg)
if self.revocation_message is not None:
| python | {
"resource": ""
} |
q270568 | ObjectDefaults.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Read the data encoding the ObjectDefaults structure and decode it into
its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidKmipEncoding: Raised if the object type or attributes are
missing from the encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the ObjectDefaults structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the ObjectDefaults object.".format(
kmip_version.value
)
)
super(ObjectDefaults, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer | python | {
"resource": ""
} |
q270569 | ObjectDefaults.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Write the ObjectDefaults structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
Attributes structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the object type or attributes fields are
not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the ObjectDefaults structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the ObjectDefaults object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
if self._object_type:
| python | {
"resource": ""
} |
q270570 | DefaultsInformation.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Read the data encoding the DefaultsInformation structure and decode it
into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidKmipEncoding: Raised if the object defaults are missing
from the encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the DefaultsInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the DefaultsInformation "
"object.".format(
kmip_version.value
)
| python | {
"resource": ""
} |
q270571 | DefaultsInformation.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Write the DefaultsInformation structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
Attributes structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the object defaults field is not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the DefaultsInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_2_0:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the DefaultsInformation "
"object.".format(
kmip_version.value
)
| python | {
"resource": ""
} |
q270572 | RNGParameters.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Read the data encoding the RNGParameters structure and decode it
into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidKmipEncoding: Raised if the RNG algorithm is missing from
the encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the RNGParameters structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the RNGParameters object.".format(
kmip_version.value
)
)
super(RNGParameters, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.RNG_ALGORITHM, local_buffer):
rng_algorithm = primitives.Enumeration(
enums.RNGAlgorithm,
tag=enums.Tags.RNG_ALGORITHM
)
rng_algorithm.read(local_buffer, kmip_version=kmip_version)
self._rng_algorithm = rng_algorithm
else:
raise exceptions.InvalidKmipEncoding(
"The RNGParameters encoding is missing the RNG algorithm."
)
if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_ALGORITHM, local_buffer):
cryptographic_algorithm = primitives.Enumeration(
enums.CryptographicAlgorithm,
tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM
)
cryptographic_algorithm.read(
local_buffer,
kmip_version=kmip_version
)
self._cryptographic_algorithm = cryptographic_algorithm
if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_LENGTH, local_buffer):
cryptographic_length = primitives.Integer(
tag=enums.Tags.CRYPTOGRAPHIC_LENGTH
)
cryptographic_length.read(local_buffer, kmip_version=kmip_version)
self._cryptographic_length = cryptographic_length
if self.is_tag_next(enums.Tags.HASHING_ALGORITHM, local_buffer):
hashing_algorithm = primitives.Enumeration(
enums.HashingAlgorithm,
| python | {
"resource": ""
} |
q270573 | RNGParameters.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Write the RNGParameters structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
Attributes structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the RNG algorithm field is not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the RNGParameters structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the RNGParameters object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
if self._rng_algorithm:
self._rng_algorithm.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The RNGParameters structure is missing the RNG algorithm "
"field."
)
if self._cryptographic_algorithm:
self._cryptographic_algorithm.write(
local_buffer,
kmip_version=kmip_version
)
if self._cryptographic_length:
self._cryptographic_length.write(
local_buffer,
kmip_version=kmip_version
)
if self._hashing_algorithm:
self._hashing_algorithm.write(
local_buffer,
kmip_version=kmip_version
) | python | {
"resource": ""
} |
q270574 | ProfileInformation.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Read the data encoding the ProfileInformation structure and decode it
into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidKmipEncoding: Raised if the profile name is missing from
the encoding.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the ProfileInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the ProfileInformation "
"object.".format(
kmip_version.value
)
)
super(ProfileInformation, self).read(
input_buffer,
kmip_version=kmip_version
)
| python | {
"resource": ""
} |
q270575 | ProfileInformation.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Write the ProfileInformation structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
ProfileInformation structure data, supporting a write method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the profile name field is not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the ProfileInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the ProfileInformation "
"object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
| python | {
"resource": ""
} |
q270576 | ValidationInformation.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Write the ValidationInformation structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
ValidationInformation structure data, supporting a write
method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
InvalidField: Raised if the validation authority type, validation
version major, validation type, and/or validation level fields
are not defined.
VersionNotSupported: Raised when a KMIP version is provided that
does not support the ValidationInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the ValidationInformation "
"object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
if self._validation_authority_type:
self._validation_authority_type.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The ValidationInformation structure is missing the "
"validation authority type field."
)
if self._validation_authority_country:
self._validation_authority_country.write(
local_buffer,
| python | {
"resource": ""
} |
q270577 | CapabilityInformation.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Read the data encoding the CapabilityInformation structure and decode
it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 2.0.
Raises:
VersionNotSupported: Raised when a KMIP version is provided that
does not support the CapabilityInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the CapabilityInformation "
"object.".format(
kmip_version.value
)
)
super(CapabilityInformation, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.STREAMING_CAPABILITY, local_buffer):
streaming_capability = primitives.Boolean(
tag=enums.Tags.STREAMING_CAPABILITY
)
streaming_capability.read(local_buffer, kmip_version=kmip_version)
self._streaming_capability = streaming_capability
if self.is_tag_next(enums.Tags.ASYNCHRONOUS_CAPABILITY, local_buffer):
asynchronous_capability = primitives.Boolean(
tag=enums.Tags.ASYNCHRONOUS_CAPABILITY
)
asynchronous_capability.read(
local_buffer,
kmip_version=kmip_version
)
self._asynchronous_capability = asynchronous_capability
if self.is_tag_next(enums.Tags.ATTESTATION_CAPABILITY, local_buffer):
attestation_capability = primitives.Boolean(
| python | {
"resource": ""
} |
q270578 | CapabilityInformation.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
"""
Write the CapabilityInformation structure encoding to the data stream.
Args:
output_buffer (stream): A data stream in which to encode
CapabilityInformation structure data, supporting a write
method.
kmip_version (enum): A KMIPVersion enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 2.0.
Raises:
VersionNotSupported: Raised when a KMIP version is provided that
does not support the CapabilityInformation structure.
"""
if kmip_version < enums.KMIPVersion.KMIP_1_3:
raise exceptions.VersionNotSupported(
"KMIP {} does not support the CapabilityInformation "
"object.".format(
kmip_version.value
)
)
local_buffer = BytearrayStream()
if self._streaming_capability:
self._streaming_capability.write(
local_buffer,
kmip_version=kmip_version
)
if self._asynchronous_capability:
self._asynchronous_capability.write(
local_buffer,
kmip_version=kmip_version
)
if self._attestation_capability:
self._attestation_capability.write(
local_buffer,
kmip_version=kmip_version
)
if kmip_version >= enums.KMIPVersion.KMIP_1_4:
if self._batch_undo_capability:
self._batch_undo_capability.write(
local_buffer,
kmip_version=kmip_version
)
if self._batch_continue_capability:
| python | {
"resource": ""
} |
q270579 | KmipServer.stop | test | def stop(self):
"""
Stop the server.
Halt server client connections and clean up any existing connection
threads.
Raises:
NetworkingError: Raised if a failure occurs while sutting down
or closing the TLS server socket.
"""
self._logger.info("Cleaning up remaining connection threads.")
for thread in threading.enumerate():
if thread is not threading.current_thread():
try:
thread.join(10.0)
except Exception as e:
self._logger.info(
"Error occurred while attempting to cleanup thread: "
"{0}".format(thread.name)
)
self._logger.exception(e)
else:
if thread.is_alive():
self._logger.warning(
"Cleanup failed for thread: {0}. Thread is "
"still alive".format(thread.name)
)
else:
self._logger.info(
"Cleanup succeeded for thread: {0}".format(
thread.name
)
| python | {
"resource": ""
} |
q270580 | KmipServer.serve | test | def serve(self):
"""
Serve client connections.
Begin listening for client connections, spinning off new KmipSessions
as connections are handled. Set up signal handling to shutdown
connection service as needed.
"""
self._socket.listen(5)
def _signal_handler(signal_number, stack_frame):
self._is_serving = False
# Python3.5+ silently ignores SIGINT and retries system calls if
# the signal handler does not raise an exception. Explicitly
# detect SIGINT and raise a KeyboardInterrupt exception to regain
# old functionality.
if signal_number == signal.SIGINT:
raise KeyboardInterrupt("SIGINT received")
signal.signal(signal.SIGINT, _signal_handler)
signal.signal(signal.SIGTERM, _signal_handler)
self._logger.info("Starting connection service...")
while self._is_serving:
try:
connection, address = self._socket.accept()
except socket.timeout:
# Setting the default socket timeout to break hung connections
# will cause accept to periodically raise socket.timeout. This
# is expected behavior, so ignore it and | python | {
"resource": ""
} |
q270581 | LocateRequestPayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Locate request payload and decode it into
its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the attributes structure is missing
from the encoded payload for KMIP 2.0+ encodings.
"""
super(LocateRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.MAXIMUM_ITEMS, local_buffer):
self._maximum_items = primitives.Integer(
tag=enums.Tags.MAXIMUM_ITEMS
)
self._maximum_items.read(
local_buffer,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.OFFSET_ITEMS, local_buffer):
self._offset_items = primitives.Integer(
tag=enums.Tags.OFFSET_ITEMS
)
self._offset_items.read(
local_buffer,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.STORAGE_STATUS_MASK, local_buffer):
self._storage_status_mask = primitives.Integer(
tag=enums.Tags.STORAGE_STATUS_MASK
)
self._storage_status_mask.read(
local_buffer,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.OBJECT_GROUP_MEMBER, local_buffer):
self._object_group_member = primitives.Enumeration(
enums.ObjectGroupMember,
tag=enums.Tags.OBJECT_GROUP_MEMBER
)
| python | {
"resource": ""
} |
q270582 | LocateRequestPayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Locate request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if self._maximum_items:
self._maximum_items.write(local_buffer, kmip_version=kmip_version)
if self._offset_items:
self._offset_items.write(local_buffer, kmip_version=kmip_version)
if self._storage_status_mask:
self._storage_status_mask.write(
local_buffer,
kmip_version=kmip_version
)
if self._object_group_member:
self._object_group_member.write(
local_buffer,
kmip_version=kmip_version
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._attributes:
for attribute in self.attributes:
attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._attributes:
# TODO (ph) Add a new utility to avoid using TemplateAttributes
template_attribute = objects.TemplateAttribute( | python | {
"resource": ""
} |
q270583 | LocateResponsePayload.read | test | def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Locate response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(LocateResponsePayload, self).read(
| python | {
"resource": ""
} |
q270584 | LocateResponsePayload.write | test | def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Locate response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if self._located_items:
self._located_items.write(local_buffer, kmip_version=kmip_version)
| python | {
"resource": ""
} |
q270585 | CryptographyEngine.create_symmetric_key | test | def create_symmetric_key(self, algorithm, length):
"""
Create a symmetric key.
Args:
algorithm(CryptographicAlgorithm): An enumeration specifying the
algorithm for which the created key will be compliant.
length(int): The length of the key to be created. This value must
be compliant with the constraints of the provided algorithm.
Returns:
dict: A dictionary containing the key data, with the following
key/value fields:
* value - the bytes of the key
* format - a KeyFormatType enumeration for the bytes format
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
Example:
>>> engine = CryptographyEngine()
>>> key = engine.create_symmetric_key(
... CryptographicAlgorithm.AES, 256)
"""
if algorithm not in self._symmetric_key_algorithms.keys():
raise exceptions.InvalidField(
"The cryptographic algorithm {0} is not a supported symmetric "
"key algorithm.".format(algorithm)
| python | {
"resource": ""
} |
q270586 | CryptographyEngine.create_asymmetric_key_pair | test | def create_asymmetric_key_pair(self, algorithm, length):
"""
Create an asymmetric key pair.
Args:
algorithm(CryptographicAlgorithm): An enumeration specifying the
algorithm for which the created keys will be compliant.
length(int): The length of the keys to be created. This value must
be compliant with the constraints of the provided algorithm.
Returns:
dict: A dictionary containing the public key data, with at least
the following key/value fields:
* value - the bytes of the key
* format - a KeyFormatType enumeration for the bytes format
dict: A dictionary containing the private key data, identical in
structure to the one above.
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
| python | {
"resource": ""
} |
q270587 | CryptographyEngine.mac | test | def mac(self, algorithm, key, data):
"""
Generate message authentication code.
Args:
algorithm(CryptographicAlgorithm): An enumeration specifying the
algorithm for which the MAC operation will use.
key(bytes): secret key used in the MAC operation
data(bytes): The data to be MACed.
Returns:
bytes: The MACed data
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
Example:
>>> engine = CryptographyEngine()
>>> mac_data = engine.mac(
... CryptographicAlgorithm.HMAC-SHA256, b'\x01\x02\x03\x04',
... b'\x05\x06\x07\x08')
"""
mac_data = None
if algorithm in self._hash_algorithms.keys():
self.logger.info(
"Generating a hash-based message authentication code using "
"{0}".format(algorithm.name)
)
hash_algorithm = self._hash_algorithms.get(algorithm)
try:
h = hmac.HMAC(key, hash_algorithm(), backend=default_backend())
h.update(data)
mac_data = h.finalize()
except Exception as e:
self.logger.exception(e)
raise exceptions.CryptographicFailure(
"An error occurred while computing an HMAC. "
"See the server log for more information."
)
elif algorithm in self._symmetric_key_algorithms.keys():
self.logger.info(
"Generating a cipher-based message authentication code using "
| python | {
"resource": ""
} |
q270588 | CryptographyEngine.encrypt | test | def encrypt(self,
encryption_algorithm,
encryption_key,
plain_text,
cipher_mode=None,
padding_method=None,
iv_nonce=None,
hashing_algorithm=None):
"""
Encrypt data using symmetric or asymmetric encryption.
Args:
encryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the encryption algorithm to use for encryption.
encryption_key (bytes): The bytes of the encryption key to use for
encryption.
plain_text (bytes): The bytes to be encrypted.
cipher_mode (BlockCipherMode): An enumeration specifying the
block cipher mode to use with the encryption algorithm.
Required in the general case. Optional if the encryption
algorithm is RC4 (aka ARC4). If optional, defaults to None.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use on the data before encryption. Required
if the cipher mode is for block ciphers (e.g., CBC, ECB).
Optional otherwise, defaults to None.
iv_nonce (bytes): The IV/nonce value to use to initialize the mode
of the encryption algorithm. Optional, defaults to None. If
required and not provided, it will be autogenerated and
returned with the cipher text.
hashing_algorithm (HashingAlgorithm): An enumeration specifying
the hashing algorithm to use with the encryption algorithm,
if needed. Required for OAEP-based asymmetric encryption.
Optional, defaults to None.
Returns:
dict: A dictionary containing the encrypted data, with at least
the following key/value fields:
* cipher_text - the bytes of the encrypted data
* iv_nonce - the bytes of the IV/counter/nonce used if it
was needed by the encryption scheme and if it was
automatically generated for the encryption
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
| python | {
"resource": ""
} |
q270589 | CryptographyEngine._encrypt_symmetric | test | def _encrypt_symmetric(
self,
encryption_algorithm,
encryption_key,
plain_text,
cipher_mode=None,
padding_method=None,
iv_nonce=None):
"""
Encrypt data using symmetric encryption.
Args:
encryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the symmetric encryption algorithm to use for
encryption.
encryption_key (bytes): The bytes of the symmetric key to use for
encryption.
plain_text (bytes): The bytes to be encrypted.
cipher_mode (BlockCipherMode): An enumeration specifying the
block cipher mode to use with the encryption algorithm.
Required in the general case. Optional if the encryption
algorithm is RC4 (aka ARC4). If optional, defaults to None.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use on the data before encryption. Required
if the cipher mode is for block ciphers (e.g., CBC, ECB).
Optional otherwise, defaults to None.
iv_nonce (bytes): The IV/nonce value to use to initialize the mode
of the encryption algorithm. Optional, defaults to None. If
required and not provided, it will be autogenerated and
returned with the cipher text.
Returns:
dict: A dictionary containing the encrypted data, with at least
the following key/value fields:
* cipher_text - the bytes of the encrypted data
* iv_nonce - the bytes of the IV/counter/nonce used if it
was needed by the encryption scheme and if it was
automatically generated for the encryption
Raises:
InvalidField: Raised when the algorithm is unsupported or the
encryption key is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
"""
# Set up the algorithm
algorithm = self._symmetric_key_algorithms.get(
encryption_algorithm,
None
)
if algorithm is None:
raise exceptions.InvalidField(
"Encryption algorithm '{0}' is not a supported symmetric "
"encryption algorithm.".format(encryption_algorithm)
)
try:
algorithm = algorithm(encryption_key) | python | {
"resource": ""
} |
q270590 | CryptographyEngine._encrypt_asymmetric | test | def _encrypt_asymmetric(self,
encryption_algorithm,
encryption_key,
plain_text,
padding_method,
hashing_algorithm=None):
"""
Encrypt data using asymmetric encryption.
Args:
encryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the asymmetric encryption algorithm to use for
encryption. Required.
encryption_key (bytes): The bytes of the public key to use for
encryption. Required.
plain_text (bytes): The bytes to be encrypted. Required.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use with the asymmetric encryption
algorithm. Required.
hashing_algorithm (HashingAlgorithm): An enumeration specifying
the hashing algorithm to use with the encryption padding
method. Required, if the padding method is OAEP. Optional
otherwise, defaults to None.
Returns:
dict: A dictionary containing the encrypted data, with at least
the following key/value field:
* cipher_text - the bytes of the encrypted data
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
"""
if encryption_algorithm == enums.CryptographicAlgorithm.RSA:
if padding_method == enums.PaddingMethod.OAEP:
hash_algorithm = self._encryption_hash_algorithms.get(
hashing_algorithm
)
if hash_algorithm is None:
raise exceptions.InvalidField(
"The hashing algorithm '{0}' is not supported for "
"asymmetric encryption.".format(hashing_algorithm)
)
| python | {
"resource": ""
} |
q270591 | CryptographyEngine._decrypt_asymmetric | test | def _decrypt_asymmetric(
self,
decryption_algorithm,
decryption_key,
cipher_text,
padding_method,
hashing_algorithm=None):
"""
Encrypt data using asymmetric decryption.
Args:
decryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the asymmetric decryption algorithm to use for
decryption. Required.
decryption_key (bytes): The bytes of the private key to use for
decryption. Required.
cipher_text (bytes): The bytes to be decrypted. Required.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use with the asymmetric decryption
algorithm. Required.
hashing_algorithm (HashingAlgorithm): An enumeration specifying
the hashing algorithm to use with the decryption padding
method. Required, if the padding method is OAEP. Optional
otherwise, defaults to None.
Returns:
dict: A dictionary containing the decrypted data, with at least
the following key/value field:
* plain_text - the bytes of the decrypted data
Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.
"""
if decryption_algorithm == enums.CryptographicAlgorithm.RSA:
if padding_method == enums.PaddingMethod.OAEP:
hash_algorithm = self._encryption_hash_algorithms.get(
hashing_algorithm
)
if hash_algorithm is None:
raise exceptions.InvalidField(
"The hashing algorithm '{0}' is not supported for "
"asymmetric decryption.".format(hashing_algorithm)
)
padding_method = asymmetric_padding.OAEP(
mgf=asymmetric_padding.MGF1(
| python | {
"resource": ""
} |
q270592 | CryptographyEngine._create_rsa_key_pair | test | def _create_rsa_key_pair(self, length, public_exponent=65537):
"""
Create an RSA key pair.
Args:
length(int): The length of the keys to be created. This value must
be compliant with the constraints of the provided algorithm.
public_exponent(int): The value of the public exponent needed to
generate the keys. Usually a small Fermat prime number.
Optional, defaults to 65537.
Returns:
dict: A dictionary containing the public key data, with the
following key/value fields:
* value - the bytes of the key
* format - a KeyFormatType enumeration for the bytes format
* public_exponent - the public exponent integer
dict: A dictionary containing the private key data, identical in
structure to the one above.
Raises:
CryptographicFailure: Raised when the key generation process
| python | {
"resource": ""
} |
q270593 | CryptographyEngine.derive_key | test | def derive_key(self,
derivation_method,
derivation_length,
derivation_data=None,
key_material=None,
hash_algorithm=None,
salt=None,
iteration_count=None,
encryption_algorithm=None,
cipher_mode=None,
padding_method=None,
iv_nonce=None):
"""
Derive key data using a variety of key derivation functions.
Args:
derivation_method (DerivationMethod): An enumeration specifying
the key derivation method to use. Required.
derivation_length (int): An integer specifying the size of the
derived key data in bytes. Required.
derivation_data (bytes): The non-cryptographic bytes to be used
in the key derivation process (e.g., the data to be encrypted,
hashed, HMACed). Required in the general case. Optional if the
derivation method is Hash and the key material is provided.
Optional, defaults to None.
key_material (bytes): The bytes of the key material to use for
key derivation. Required in the general case. Optional if
the derivation_method is HASH and derivation_data is provided.
Optional, defaults to None.
hash_algorithm (HashingAlgorithm): An enumeration specifying the
hashing algorithm to use with the key derivation method.
Required in the general case, optional if the derivation
method specifies encryption. Optional, defaults to None.
salt (bytes): Bytes representing a randomly generated salt.
Required if the derivation method is PBKDF2. Optional,
defaults to None.
iteration_count (int): An integer representing the number of
iterations to use when deriving key material. Required if
the derivation method is PBKDF2. Optional, defaults to None.
encryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the symmetric encryption algorithm to use for
encryption-based key derivation. Required if the derivation
method specifies encryption. Optional, defaults to None.
cipher_mode (BlockCipherMode): An enumeration specifying the
block cipher mode to use with the encryption algorithm.
Required in in the general case if the derivation method
specifies encryption and the encryption algorithm is
specified. Optional if the encryption algorithm is RC4 (aka
ARC4). Optional, defaults to None.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use on the data before encryption. Required
in in the general case if the derivation method specifies
encryption and the encryption algorithm is specified. Required
if the cipher mode is for block ciphers (e.g., CBC, ECB).
Optional otherwise, defaults to None.
iv_nonce (bytes): The IV/nonce value to use to initialize the mode
of the encryption algorithm. Required in the general case if
the derivation method specifies encryption and the encryption
algorithm is specified. Optional, defaults to None. If
required and not provided, it will be autogenerated.
Returns:
bytes: the bytes of the derived data
Raises:
InvalidField: Raised when cryptographic data and/or settings are
unsupported or incompatible with the derivation method.
Example:
>>> engine = CryptographyEngine()
>>> result = engine.derive_key(
... derivation_method=enums.DerivationMethod.HASH,
... derivation_length=16,
... derivation_data=b'abc',
... hash_algorithm=enums.HashingAlgorithm.MD5
... )
>>> result
b'\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr'
"""
if derivation_method == enums.DerivationMethod.ENCRYPT:
result = self.encrypt(
encryption_algorithm=encryption_algorithm,
encryption_key=key_material,
plain_text=derivation_data,
cipher_mode=cipher_mode,
padding_method=padding_method,
iv_nonce=iv_nonce
)
return result.get('cipher_text')
else:
# Handle key derivation functions that use hash algorithms
# Set up the hashing algorithm
if hash_algorithm is None:
raise exceptions.InvalidField("Hash algorithm is required.")
hashing_algorithm = self._encryption_hash_algorithms.get(
| python | {
"resource": ""
} |
q270594 | CryptographyEngine._create_RSA_private_key | test | def _create_RSA_private_key(self,
bytes):
"""
Instantiates an RSA key from bytes.
Args:
bytes (byte string): Bytes of RSA private key.
Returns:
private_key
(cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
RSA private key created from key bytes.
"""
try:
private_key = serialization.load_pem_private_key(
bytes,
| python | {
"resource": ""
} |
q270595 | CryptographyEngine.verify_signature | test | def verify_signature(self,
signing_key,
message,
signature,
padding_method,
signing_algorithm=None,
hashing_algorithm=None,
digital_signature_algorithm=None):
"""
Verify a message signature.
Args:
signing_key (bytes): The bytes of the signing key to use for
signature verification. Required.
message (bytes): The bytes of the message that corresponds with
the signature. Required.
signature (bytes): The bytes of the signature to be verified.
Required.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use during signature verification. Required.
signing_algorithm (CryptographicAlgorithm): An enumeration
specifying the cryptographic algorithm to use for signature
verification. Only RSA is supported. Optional, must match the
algorithm specified by the digital signature algorithm if both
are provided. Defaults to None.
hashing_algorithm (HashingAlgorithm): An enumeration specifying
the hashing algorithm to use with the cryptographic algortihm,
if needed. Optional, must match the algorithm specified by the
digital signature algorithm if both are provided. Defaults to
None.
digital_signature_algorithm (DigitalSignatureAlgorithm): An
enumeration specifying both the cryptographic and hashing
algorithms to use for signature verification. Optional, must
match the cryptographic and hashing algorithms if both are
provided. Defaults to None.
Returns:
boolean: the result of signature verification, True for valid
signatures, False for invalid signatures
Raises:
InvalidField: Raised when various settings or values are invalid.
CryptographicFailure: Raised when the signing key bytes cannot be
loaded, or when the signature verification process fails
unexpectedly.
"""
backend = default_backend()
hash_algorithm = None
dsa_hash_algorithm = None
dsa_signing_algorithm = None
if hashing_algorithm:
hash_algorithm = self._encryption_hash_algorithms.get(
hashing_algorithm
)
if digital_signature_algorithm:
algorithm_pair = self._digital_signature_algorithms.get(
digital_signature_algorithm
)
if algorithm_pair:
dsa_hash_algorithm = algorithm_pair[0]
dsa_signing_algorithm = algorithm_pair[1]
if dsa_hash_algorithm and dsa_signing_algorithm:
if hash_algorithm and (hash_algorithm != dsa_hash_algorithm):
raise exceptions.InvalidField(
"The hashing algorithm does not match the digital "
"signature algorithm."
)
if (signing_algorithm and
(signing_algorithm != dsa_signing_algorithm)):
raise exceptions.InvalidField(
"The signing algorithm does not match the digital "
"signature algorithm."
)
signing_algorithm = dsa_signing_algorithm
hash_algorithm = dsa_hash_algorithm
if signing_algorithm == enums.CryptographicAlgorithm.RSA:
if padding_method == enums.PaddingMethod.PSS:
if hash_algorithm:
padding = asymmetric_padding.PSS(
| python | {
"resource": ""
} |
q270596 | SignResponsePayload.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Sign response payload and decode it.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the unique_identifier or signature attributes
are missing from the encoded payload.
"""
super(SignResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
| python | {
"resource": ""
} |
q270597 | SignResponsePayload.write | test | def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Sign response to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
Raises:
ValueError: Raised if the unique_identifier or signature
attributes are not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"invalid payload missing the unique identifier attribute"
)
if self._signature_data:
| python | {
"resource": ""
} |
q270598 | GetUsageAllocationRequestPayload.read | test | def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetUsageAllocation request payload and
decode it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(GetUsageAllocationRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
| python | {
"resource": ""
} |
q270599 | protocol_version_to_kmip_version | test | def protocol_version_to_kmip_version(value):
"""
Convert a ProtocolVersion struct to its KMIPVersion enumeration equivalent.
Args:
value (ProtocolVersion): A ProtocolVersion struct to be converted into
a KMIPVersion enumeration.
Returns:
KMIPVersion: The enumeration equivalent of the struct. If the struct
cannot be converted to a valid enumeration, None is returned.
"""
if not isinstance(value, ProtocolVersion):
return None
if value.major == 1:
if value.minor == 0:
return enums.KMIPVersion.KMIP_1_0
elif value.minor == | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.