docstring
stringlengths
52
499
function
stringlengths
67
35.2k
__index_level_0__
int64
52.6k
1.16M
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 version with which the object will be encoded. Optional, defaults to KMIP 1.0.
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(Boolean, self).write(ostream, kmip_version=kmip_version) self.write_value(ostream, kmip_version=kmip_version)
380,763
Create a DateTime. Args: value (int): The value of the DateTime in number of seconds since the Epoch. See the time package for additional information. Optional, defaults to the current time. tag (Tags): An enumeration defining the tag of the LongInteger. Optional, defaults to Tags.DEFAULT.
def __init__(self, value=None, tag=enums.Tags.DEFAULT): if value is None: value = int(time.time()) super(DateTime, self).__init__(value, tag) self.type = enums.Types.DATE_TIME
380,779
Create a Key object. Args: key_wrapping_data(dict): A dictionary containing key wrapping data settings, describing how the key value has been wrapped. Optional, defaults to None.
def __init__(self, key_wrapping_data=None): super(Key, self).__init__() self.cryptographic_algorithm = None self.cryptographic_length = None self.key_format_type = None self.key_wrapping_data = key_wrapping_data # All remaining attributes are not considered part of the public API # and are subject to change. self._cryptographic_parameters = list() # The following attributes are placeholders for attributes that are # unsupported by kmip.core self._usage_limits = None
380,805
Create a Certificate. Args: certificate_type(CertificateType): An enumeration defining the type of the certificate. value(bytes): The bytes representing the certificate. masks(list): A list of CryptographicUsageMask enumerations defining how the certificate will be used. name(string): The string name of the certificate.
def __init__(self, certificate_type, value, masks=None, name='Certificate'): super(Certificate, self).__init__() self._object_type = enums.ObjectType.CERTIFICATE self.value = value self.certificate_type = certificate_type self.names = [name] if masks: self.cryptographic_usage_masks = masks # All remaining attributes are not considered part of the public API # and are subject to change. self._cryptographic_algorithm = None self._cryptographic_length = None self._certificate_length = None # The following attributes are placeholders for attributes that are # unsupported by kmip.core self._cryptographic_parameters = list() self._digital_signature_algorithm = list() self.validate()
380,814
Create an X509Certificate. Args: value(bytes): The bytes representing the certificate. masks(list): A list of CryptographicUsageMask enumerations defining how the certificate will be used. name(string): The string name of the certificate.
def __init__(self, value, masks=None, name='X.509 Certificate'): super(X509Certificate, self).__init__( enums.CertificateType.X_509, value, masks, name) # All remaining attributes are not considered part of the public API # and are subject to change. # The following attributes are placeholders for attributes that are # unsupported by kmip.core self._x509_certificate_identifier = None self._x509_certificate_subject = None self._x509_certificate_issuer = None self.validate()
380,815
Create a SecretData object. Args: value(bytes): The bytes representing secret data. data_type(SecretDataType): An enumeration defining the type of the secret value. masks(list): A list of CryptographicUsageMask enumerations defining how the key will be used. name(string): The string name of the key.
def __init__(self, value, data_type, masks=None, name='Secret Data'): super(SecretData, self).__init__() self._object_type = enums.ObjectType.SECRET_DATA self.value = value self.data_type = data_type self.names = [name] if masks: self.cryptographic_usage_masks = masks # All remaining attributes are not considered part of the public API # and are subject to change. # The following attributes are placeholders for attributes that are # unsupported by kmip.core self.validate()
380,817
Create a OpaqueObject. Args: value(bytes): The bytes representing opaque data. opaque_type(OpaqueDataType): An enumeration defining the type of the opaque value. name(string): The string name of the opaque object.
def __init__(self, value, opaque_type, name='Opaque Object'): super(OpaqueObject, self).__init__() self._object_type = enums.ObjectType.OPAQUE_DATA self.value = value self.opaque_type = opaque_type self.names.append(name) # All remaining attributes are not considered part of the public API # and are subject to change. self._digest = None self._revocation_reason = None # The following attributes are placeholders for attributes that are # unsupported by kmip.core self._destroy_date = None self._compromise_occurrence_date = None self._compromise_date = None self.validate()
380,821
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
def convert_attribute_name_to_tag(value): if not isinstance(value, six.string_types): raise ValueError("The attribute name must be a string.") for entry in attribute_name_tag_table: if value == entry[0]: return entry[1] raise ValueError("Unrecognized attribute name: '{}'".format(value))
380,830
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
def convert_attribute_tag_to_name(value): if not isinstance(value, Tags): raise ValueError("The attribute tag must be a Tags enumeration.") for entry in attribute_name_tag_table: if value == entry[1]: return entry[0] raise ValueError("Unrecognized attribute tag: {}".format(value))
380,831
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: int: The composite bit mask.
def get_bit_mask_from_enumerations(enumerations): return functools.reduce( lambda x, y: x | y, [z.value for z in enumerations] )
380,832
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 which to identify enumeration values. Returns: list: A list of enumeration values corresponding to the bit mask.
def get_enumerations_from_bit_mask(enumeration, mask): return [x for x in enumeration if (x.value & mask) == x.value]
380,833
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.
def read(self, input_buffer, kmip_version=enums.KMIPVersion.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, kmip_version=kmip_version ) else: if self.is_tag_next( enums.Tags.PRIVATE_KEY_ATTRIBUTES, local_buffer ): attributes = objects.Attributes( tag=enums.Tags.PRIVATE_KEY_ATTRIBUTES ) attributes.read(local_buffer, kmip_version=kmip_version) self._private_key_template_attribute = \ objects.convert_attributes_to_template_attribute( attributes ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next( enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE, local_buffer ): self._public_key_template_attribute = \ objects.TemplateAttribute( tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE ) self._public_key_template_attribute.read( local_buffer, kmip_version=kmip_version ) else: if self.is_tag_next( enums.Tags.PUBLIC_KEY_ATTRIBUTES, local_buffer ): attributes = objects.Attributes( tag=enums.Tags.PUBLIC_KEY_ATTRIBUTES ) attributes.read(local_buffer, kmip_version=kmip_version) self._public_key_template_attribute = \ objects.convert_attributes_to_template_attribute( attributes ) self.is_oversized(local_buffer)
380,840
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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.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 ) attributes.write(local_buffer, kmip_version=kmip_version) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._private_key_template_attribute is not None: self._private_key_template_attribute.write( local_buffer, kmip_version=kmip_version ) else: if self._private_key_template_attribute is not None: attributes = objects.convert_template_attribute_to_attributes( self._private_key_template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._public_key_template_attribute is not None: self._public_key_template_attribute.write( local_buffer, kmip_version=kmip_version ) else: if self._public_key_template_attribute is not None: attributes = objects.convert_template_attribute_to_attributes( self._public_key_template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) self.length = local_buffer.length() super(CreateKeyPairRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
380,841
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.
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): super(GetAttributeListRequestPayload, 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: self._unique_identifier = None self.is_oversized(local_buffer)
380,853
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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(GetAttributeListRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
380,854
Construct a GetAttributeList response payload. Args: unique_identifier (string): The ID of the managed object with which the retrieved attribute names should be associated. Optional, defaults to None. attribute_names: A list of strings identifying the names of the attributes associated with the managed object. Optional, defaults to None.
def __init__(self, unique_identifier=None, attribute_names=None): super(GetAttributeListResponsePayload, self).__init__( enums.Tags.RESPONSE_PAYLOAD ) self._unique_identifier = None self._attribute_names = list() self.unique_identifier = unique_identifier self.attribute_names = attribute_names
380,856
Construct a Create request payload structure. Args: object_type (enum): An ObjectType enumeration specifying the type of object to create. Optional, defaults to None. Required for read/write. template_attribute (TemplateAttribute): A TemplateAttribute structure containing a set of attributes to set on the new object. Optional, defaults to None. Required for read/write.
def __init__(self, object_type=None, template_attribute=None): super(CreateRequestPayload, self).__init__( tag=enums.Tags.REQUEST_PAYLOAD ) self._object_type = None self._template_attribute = None self.object_type = object_type self.template_attribute = template_attribute
380,889
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.
def convert(self, obj): 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) elif isinstance(obj, pobjects.Certificate): return self._build_core_certificate(obj) elif isinstance(obj, secrets.Certificate): return self._build_pie_certificate(obj) elif isinstance(obj, pobjects.SecretData): return self._build_core_secret_data(obj) elif isinstance(obj, secrets.SecretData): return self._build_pie_secret_data(obj) elif isinstance(obj, pobjects.OpaqueObject): return self._build_core_opaque_object(obj) elif isinstance(obj, secrets.OpaqueObject): return self._build_pie_opaque_object(obj) else: raise TypeError("object type unsupported and cannot be converted")
380,902
Create an AttributePolicy. Args: version (ProtocolVersion): The KMIP protocol version under which this set of attribute policies should be evaluated. Required.
def __init__(self, version): self._version = version self._attribute_rule_sets = { 'Unique Identifier': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Name': AttributeRuleSet( False, ('client', ), True, True, True, True, ( enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Object Type': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Cryptographic Algorithm': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Cryptographic Length': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Cryptographic Parameters': AttributeRuleSet( False, ('client', ), False, True, True, True, ( enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Cryptographic Domain Parameters': AttributeRuleSet( False, ('client', ), False, False, False, False, ( enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Certificate Type': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 0) ), 'Certificate Length': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 1) ), 'X.509 Certificate Identifier': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( # TODO (peterhamilton) Enforce only on X.509 certificates enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 1) ), 'X.509 Certificate Subject': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( # TODO (peterhamilton) Enforce only on X.509 certificates enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 1) ), 'X.509 Certificate Issuer': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( # TODO (peterhamilton) Enforce only on X.509 certificates enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 1) ), 'Certificate Identifier': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 0), contents.ProtocolVersion(1, 1) ), 'Certificate Subject': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 0), contents.ProtocolVersion(1, 1) ), 'Certificate Issuer': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 0), contents.ProtocolVersion(1, 1) ), 'Digital Signature Algorithm': AttributeRuleSet( True, ('server', ), False, False, False, # TODO (peterhamilton) Enforce only for X.509 certificates False, # True for PGP certificates ( enums.Operation.REGISTER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY ), ( enums.ObjectType.CERTIFICATE, ), contents.ProtocolVersion(1, 1) ), 'Digest': AttributeRuleSet( True, # If the server has access to the data ('server', ), False, False, False, True, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Operation Policy Name': AttributeRuleSet( False, ('server', 'client'), True, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Cryptographic Usage Mask': AttributeRuleSet( True, ('server', 'client'), True, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA ), contents.ProtocolVersion(1, 0) ), 'Lease Time': AttributeRuleSet( False, ('server', ), True, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA ), contents.ProtocolVersion(1, 0) ), 'Usage Limits': AttributeRuleSet( False, ('server', 'client'), # Values differ based on source True, True, # Conditional on values and operations used True, # Conditional on operations used False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR, enums.Operation.GET_USAGE_ALLOCATION ), ( enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'State': AttributeRuleSet( True, ('server', ), True, False, # Only modifiable by server for certain requests False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.ACTIVATE, enums.Operation.REVOKE, enums.Operation.DESTROY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA ), contents.ProtocolVersion(1, 0) ), 'Initial Date': AttributeRuleSet( True, ('server', ), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Activation Date': AttributeRuleSet( False, ('server', 'client'), True, # Only while in Pre-Active state True, # Only while in Pre-Active state False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.ACTIVATE, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA ), contents.ProtocolVersion(1, 0) ), 'Process Start Date': AttributeRuleSet( False, ('server', 'client'), True, # Only while in Pre-Active / Active state and more True, # Only while in Pre-Active / Active state and more False, False, ( enums.Operation.CREATE, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.REKEY ), ( enums.ObjectType.SYMMETRIC_KEY, # Only SplitKeys of SymmetricKeys enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Protect Stop Date': AttributeRuleSet( False, ('server', 'client'), True, # Only while in Pre-Active / Active state and more True, # Only while in Pre-Active / Active state and more False, False, ( enums.Operation.CREATE, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.REKEY ), ( enums.ObjectType.SYMMETRIC_KEY, # Only SplitKeys of SymmetricKeys enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE ), contents.ProtocolVersion(1, 0) ), 'Deactivation Date': AttributeRuleSet( False, ('server', 'client'), True, # Only while in Pre-Active / Active state True, # Only while in Pre-Active / Active state False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.REVOKE, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA ), contents.ProtocolVersion(1, 0) ), 'Destroy Date': AttributeRuleSet( False, ('server', ), False, False, False, False, ( enums.Operation.DESTROY, ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Compromise Occurrence Date': AttributeRuleSet( False, ('server', ), False, False, False, False, ( enums.Operation.REVOKE, ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Compromise Date': AttributeRuleSet( False, ('server', ), False, False, False, False, ( enums.Operation.REVOKE, ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Revocation Reason': AttributeRuleSet( False, ('server', ), True, False, False, False, ( enums.Operation.REVOKE, ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Archive Date': AttributeRuleSet( False, ('server', ), False, False, False, False, ( enums.Operation.ARCHIVE, ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Object Group': AttributeRuleSet( False, ('server', 'client'), False, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Fresh': AttributeRuleSet( False, ('server', 'client'), True, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 1) ), 'Link': AttributeRuleSet( False, ('server', ), True, True, True, True, ( enums.Operation.CREATE_KEY_PAIR, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Application Specific Information': AttributeRuleSet( False, ('server', 'client'), # Only if omitted in client request True, # Only if attribute omitted in client request True, True, True, ( enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Contact Information': AttributeRuleSet( False, ('server', 'client'), True, True, True, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Last Change Date': AttributeRuleSet( True, ('server', ), True, False, False, False, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.ACTIVATE, enums.Operation.REVOKE, enums.Operation.DESTROY, enums.Operation.ARCHIVE, enums.Operation.RECOVER, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR, enums.Operation.ADD_ATTRIBUTE, enums.Operation.MODIFY_ATTRIBUTE, enums.Operation.DELETE_ATTRIBUTE, enums.Operation.GET_USAGE_ALLOCATION ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), 'Custom Attribute': AttributeRuleSet( False, ('server', 'client'), True, # Only for server-created attributes True, # Only for client-created attributes True, # Only for client-created attributes True, ( enums.Operation.CREATE, enums.Operation.CREATE_KEY_PAIR, enums.Operation.REGISTER, enums.Operation.DERIVE_KEY, enums.Operation.ACTIVATE, enums.Operation.REVOKE, enums.Operation.DESTROY, enums.Operation.CERTIFY, enums.Operation.RECERTIFY, enums.Operation.REKEY, enums.Operation.REKEY_KEY_PAIR ), ( enums.ObjectType.CERTIFICATE, enums.ObjectType.SYMMETRIC_KEY, enums.ObjectType.PUBLIC_KEY, enums.ObjectType.PRIVATE_KEY, enums.ObjectType.SPLIT_KEY, enums.ObjectType.TEMPLATE, enums.ObjectType.SECRET_DATA, enums.ObjectType.OPAQUE_DATA ), contents.ProtocolVersion(1, 0) ), }
380,928
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: bool: True if the attribute is supported by the current KMIP version. False otherwise.
def is_attribute_supported(self, attribute): if attribute not in self._attribute_rule_sets.keys(): return False rule_set = self._attribute_rule_sets.get(attribute) if self._version >= rule_set.version_added: return True else: return False
380,929
Check if the attribute is deprecated by the current KMIP version. Args: attribute (string): The name of the attribute (e.g., 'Unique Identifier'). Required.
def is_attribute_deprecated(self, attribute): rule_set = self._attribute_rule_sets.get(attribute) if rule_set.version_deprecated: if self._version >= rule_set.version_deprecated: return True else: return False else: return False
380,930
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.
def is_attribute_applicable_to_object_type(self, attribute, object_type): # TODO (peterhamilton) Handle applicability between certificate types rule_set = self._attribute_rule_sets.get(attribute) if object_type in rule_set.applies_to_object_types: return True else: return False
380,931
Check if the attribute is allowed to have multiple instances. Args: attribute (string): The name of the attribute (e.g., 'State'). Required.
def is_attribute_multivalued(self, attribute): # TODO (peterhamilton) Handle multivalue swap between certificate types rule_set = self._attribute_rule_sets.get(attribute) return rule_set.multiple_instances_permitted
380,932
Construct a CertificateValue byte string. Args: value (bytes): A byte string (e.g., b'\x00\x01...') containing the certificate bytes to store. Optional, defaults to the empty byte string.
def __init__(self, value=b''): super(CertificateValue, self).__init__(value, Tags.CERTIFICATE_VALUE)
380,933
Construct an Offset object. Args: value (int): An integer representing a positive change in time. Optional, defaults to None.
def __init__(self, value=None): super(Offset, self).__init__(value, Tags.OFFSET)
380,934
Construct a QueryFunction object. Args: value (QueryFunction enum): A QueryFunction enumeration value, (e.g., QueryFunction.QUERY_OPERATIONS). Optional, default to None.
def __init__(self, value=None): super(QueryFunction, self).__init__( QueryFunctionEnum, value, Tags.QUERY_FUNCTION)
380,935
Construct a VendorIdentification object. Args: value (str): A string describing a KMIP vendor. Optional, defaults to None.
def __init__(self, value=None): super(VendorIdentification, self).__init__( value, Tags.VENDOR_IDENTIFICATION)
380,936
Construct a KeyFormatType object. Args: value (KeyFormatType): A KeyFormatType enumeration value, (e.g., KeyFormatType.PKCS_1). Optional, default to KeyFormatType.RAW.
def __init__(self, value=KeyFormatTypeEnum.RAW): super(KeyFormatType, self).__init__( KeyFormatTypeEnum, value, Tags.KEY_FORMAT_TYPE)
380,939
Construct an AttributeReference structure. Args: vendor_identification (string): A string identifying the vendor associated with the attribute. Optional, defaults to None. Required for read/write. attribute_name (string): A string containing the attribute name. Optional, defaults to None. Required for read/write.
def __init__(self, vendor_identification=None, attribute_name=None): super(AttributeReference, self).__init__( tag=enums.Tags.ATTRIBUTE_REFERENCE ) self._vendor_identification = None self._attribute_name = None self.vendor_identification = vendor_identification self.attribute_name = attribute_name
380,962
Construct a Nonce struct. Args: nonce_id (bytes): A binary string representing the ID of the nonce value. Optional, defaults to None. Required for encoding and decoding. nonce_value (bytes): A binary string representing a random value. Optional, defaults to None. Required for encoding and decoding.
def __init__(self, nonce_id=None, nonce_value=None): super(Nonce, self).__init__(tag=enums.Tags.NONCE) self._nonce_id = None self._nonce_value = None self.nonce_id = nonce_id self.nonce_value = nonce_value
380,976
Construct a UsernamePasswordCredential struct. Args: username (string): The username identifying the credential. Optional, defaults to None. Required for encoding and decoding. password (string): The password associated with the username. Optional, defaults to None.
def __init__(self, username=None, password=None): super(UsernamePasswordCredential, self).__init__( tag=Tags.CREDENTIAL_VALUE ) self._username = None self._password = None self.username = username self.password = password
380,984
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.
def read(self, input_stream, kmip_version=enums.KMIPVersion.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 ) if self.is_tag_next(enums.Tags.PASSWORD, local_stream): self._password = primitives.TextString( tag=enums.Tags.PASSWORD ) self._password.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DEVICE_IDENTIFIER, local_stream): self._device_identifier = primitives.TextString( tag=enums.Tags.DEVICE_IDENTIFIER ) self._device_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.NETWORK_IDENTIFIER, local_stream): self._network_identifier = primitives.TextString( tag=enums.Tags.NETWORK_IDENTIFIER ) self._network_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MACHINE_IDENTIFIER, local_stream): self._machine_identifier = primitives.TextString( tag=enums.Tags.MACHINE_IDENTIFIER ) self._machine_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MEDIA_IDENTIFIER, local_stream): self._media_identifier = primitives.TextString( tag=enums.Tags.MEDIA_IDENTIFIER ) self._media_identifier.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
380,997
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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.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 ) if self._network_identifier is not None: self._network_identifier.write( local_stream, kmip_version=kmip_version) if self._machine_identifier is not None: self._machine_identifier.write( local_stream, kmip_version=kmip_version ) if self._media_identifier is not None: self._media_identifier.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(DeviceCredential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
380,998
Construct a Credential struct. Args: credential_type (CredentialType): An enumeration value that specifies the type of the credential struct. Optional, defaults to None. Required for encoding and decoding. credential_value (CredentialValue): The credential value corresponding to the credential type. Optional, defaults to None. Required for encoding and decoding.
def __init__(self, credential_type=None, credential_value=None): super(Credential, self).__init__(tag=Tags.CREDENTIAL) self._credential_type = None self._credential_value = None self.credential_type = credential_type self.credential_value = credential_value
381,012
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.
def read(self, input_stream, kmip_version=enums.KMIPVersion.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 ) else: raise ValueError( "Invalid struct missing the unique identifier attribute." ) if self.is_tag_next( enums.Tags.CRYPTOGRAPHIC_PARAMETERS, local_stream ): self._cryptographic_parameters = CryptographicParameters() self._cryptographic_parameters.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
381,033
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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.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 attribute." ) if self._cryptographic_parameters: self._cryptographic_parameters.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(MACSignatureKeyInformation, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,034
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.
def read(self, input_stream, kmip_version=enums.KMIPVersion.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): self._mac_signature = primitives.ByteString( tag=enums.Tags.MAC_SIGNATURE ) self._mac_signature.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE ) self._iv_counter_nonce.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
381,042
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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.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( local_stream, kmip_version=kmip_version ) if self._mac_signature: self._mac_signature.write( local_stream, kmip_version=kmip_version ) if self._iv_counter_nonce: self._iv_counter_nonce.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingData, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,043
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.
def read(self, input_stream, kmip_version=enums.KMIPVersion.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( local_stream, kmip_version=kmip_version ) attribute_names = [] while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_stream): attribute_name = primitives.TextString( tag=enums.Tags.ATTRIBUTE_NAME ) attribute_name.read(local_stream, kmip_version=kmip_version) attribute_names.append(attribute_name) self._attribute_names = attribute_names if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
381,052
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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.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( local_stream, kmip_version=kmip_version ) if self._attribute_names: for unique_identifier in self._attribute_names: unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingSpecification, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,053
Construct an ExtensionName object. Args: value (str): The string data representing the extension name. Optional, defaults to the empty string.
def __init__(self, value=''): super(ExtensionName, self).__init__(value, Tags.EXTENSION_NAME)
381,064
Construct an ExtensionTag object. Args: value (int): A number representing the extension tag. Often displayed in hex format. Optional, defaults to 0.
def __init__(self, value=0): super(ExtensionTag, self).__init__(value, Tags.EXTENSION_TAG)
381,065
Construct an ExtensionType object. Args: value (Types): A number representing a Types enumeration value, indicating the type of the extended Object. Optional, defaults to None.
def __init__(self, value=None): super(ExtensionType, self).__init__(value, Tags.EXTENSION_TYPE)
381,066
Construct an ExtensionInformation object. Args: extension_name (ExtensionName): The name of the extended Object. extension_tag (ExtensionTag): The tag of the extended Object. extension_type (ExtensionType): The type of the extended Object.
def __init__(self, extension_name=None, extension_tag=None, extension_type=None): super(ExtensionInformation, self).__init__(Tags.EXTENSION_INFORMATION) if extension_name is None: self.extension_name = ExtensionName() else: self.extension_name = extension_name self.extension_tag = extension_tag self.extension_type = extension_type self.validate()
381,067
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.
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(ExtensionInformation, self).read( istream, kmip_version=kmip_version ) tstream = BytearrayStream(istream.read(self.length)) self.extension_name.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TAG, tstream): self.extension_tag = ExtensionTag() self.extension_tag.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TYPE, tstream): self.extension_type = ExtensionType() self.extension_type.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
381,068
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.
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): tstream = BytearrayStream() self.extension_name.write(tstream, kmip_version=kmip_version) if self.extension_tag is not None: self.extension_tag.write(tstream, kmip_version=kmip_version) if self.extension_type is not None: self.extension_type.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(ExtensionInformation, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
381,069
Construct a RevocationReason object. Parameters: code(RevocationReasonCode): revocation reason code message(string): An optional revocation message
def __init__(self, code=None, message=None): super(RevocationReason, self).__init__(tag=Tags.REVOCATION_REASON) if code is not None: self.revocation_code = RevocationReasonCode(value=code) else: self.revocation_code = RevocationReasonCode() if message is not None: self.revocation_message = TextString( value=message, tag=Tags.REVOCATION_MESSAGE) else: self.revocation_message = None self.validate()
381,077
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.
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(RevocationReason, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.revocation_code = RevocationReasonCode() self.revocation_code.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.REVOCATION_MESSAGE, tstream): self.revocation_message = TextString() self.revocation_message.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
381,078
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.
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): tstream = BytearrayStream() self.revocation_code.write(tstream, kmip_version=kmip_version) if self.revocation_message is not None: self.revocation_message.write(tstream, kmip_version=kmip_version) # Write the length and value self.length = tstream.length() super(RevocationReason, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
381,079
Construct an ObjectDefaults structure. Args: object_type (enum): An ObjectType enumeration identifying the type to which the defaults pertain. Optional, defaults to None. Required for read/write. attributes (structure): An Attributes structure containing attribute values that are defaults for an object type. Optional, defaults to None. Required for read/write.
def __init__(self, object_type=None, attributes=None): super(ObjectDefaults, self).__init__(tag=enums.Tags.OBJECT_DEFAULTS) self._object_type = None self._attributes = None self.object_type = object_type self.attributes = attributes
381,081
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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.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( attributes=self.attributes ) attributes = objects.convert_template_attribute_to_attributes( template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Locate request payload is missing the attributes " "list." ) self.length = local_buffer.length() super(LocateRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
381,162
Construct a Locate response payload structure. Args: located_items (int): An integer specifying the number of matching objects found by the server. Note that this may not equal the number of object identifiers returned in this payload. Optional, defaults to None. unique_identifiers (list): A list of strings specifying the object identifiers for matching objects. Optional, defaults to None.
def __init__(self, located_items=None, unique_identifiers=None): super(LocateResponsePayload, self).__init__( enums.Tags.RESPONSE_PAYLOAD) self._located_items = None self._unique_identifiers = None self.located_items = located_items self.unique_identifiers = unique_identifiers
381,166
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.
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): super(LocateResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.LOCATED_ITEMS, local_buffer): self._located_items = primitives.Integer( tag=enums.Tags.LOCATED_ITEMS ) self._located_items.read( local_buffer, kmip_version=kmip_version ) self._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) self._unique_identifiers.append(unique_identifier) self.is_oversized(local_buffer)
381,169
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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream() if self._located_items: self._located_items.write(local_buffer, kmip_version=kmip_version) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(LocateResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
381,170
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.
def _create_RSA_private_key(self, bytes): try: private_key = serialization.load_pem_private_key( bytes, password=None, backend=default_backend() ) return private_key except Exception: private_key = serialization.load_der_private_key( bytes, password=None, backend=default_backend() ) return private_key
381,188
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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): 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: self._signature_data.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the signature attribute" ) self.length = local_stream.length() super(SignResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,195
Construct a GetUsageAllocation request payload struct. Args: unique_identifier (string): The ID of the managed object (e.g., a public key) to obtain a usage allocation for. Optional, defaults to None. usage_limits_count (int): The number of usage limits units that should be reserved for the object. Optional, defaults to None.
def __init__(self, unique_identifier=None, usage_limits_count=None): super(GetUsageAllocationRequestPayload, self).__init__( enums.Tags.REQUEST_PAYLOAD ) self._unique_identifier = None self._usage_limits_count = None self.unique_identifier = unique_identifier self.usage_limits_count = usage_limits_count
381,200
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.
def protocol_version_to_kmip_version(value): if not isinstance(value, ProtocolVersion): return None if value.major == 1: if value.minor == 0: return enums.KMIPVersion.KMIP_1_0 elif value.minor == 1: return enums.KMIPVersion.KMIP_1_1 elif value.minor == 2: return enums.KMIPVersion.KMIP_1_2 elif value.minor == 3: return enums.KMIPVersion.KMIP_1_3 elif value.minor == 4: return enums.KMIPVersion.KMIP_1_4 else: return None else: return None
381,204
Construct a ProtocolVersion struct. Args: major (int): The major protocol version number. Optional, defaults to None. minor (int): The minor protocol version number. Optional, defaults to None.
def __init__(self, major=None, minor=None): super(ProtocolVersion, self).__init__(enums.Tags.PROTOCOL_VERSION) self._major = None self._minor = None self.major = major self.minor = minor
381,205
Construct an Authentication struct. Args: credentials (list): A list of Credential structs to be used for authentication. Optional, defaults to None.
def __init__(self, credentials=None): super(Authentication, self).__init__(enums.Tags.AUTHENTICATION) self._credentials = [] self.credentials = credentials
381,219
Read the data encoding the Authentication 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.
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(Authentication, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) credentials = [] while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream): credential = objects.Credential() credential.read(local_stream, kmip_version=kmip_version) credentials.append(credential) if len(credentials) == 0: raise ValueError("Authentication encoding missing credentials.") self._credentials = credentials self.is_oversized(local_stream)
381,221
Write the data encoding the Authentication 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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): local_stream = utils.BytearrayStream() if len(self._credentials) == 0: raise ValueError("Authentication struct missing credentials.") for credential in self._credentials: credential.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(Authentication, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,222
Construct a Poll request payload struct. Args: asynchronous_correlation_value (bytes): The ID of a pending operation to poll the status of, in bytes. Optional, defaults to None.
def __init__(self, asynchronous_correlation_value=None): super(PollRequestPayload, self).__init__( enums.Tags.REQUEST_PAYLOAD ) self._asynchronous_correlation_value = None self.asynchronous_correlation_value = asynchronous_correlation_value
381,235
Construct a Certificate object. Args: certificate_type (CertificateType): The type of the certificate. Optional, defaults to None. certificate_value (bytes): The bytes of the certificate. Optional, defaults to None.
def __init__(self, certificate_type=None, certificate_value=None): super(Certificate, self).__init__(Tags.CERTIFICATE) if certificate_type is None: self.certificate_type = CertificateType() else: self.certificate_type = CertificateType(certificate_type) if certificate_value is None: self.certificate_value = CertificateValue() else: self.certificate_value = CertificateValue(certificate_value)
381,237
Read the data encoding the Certificate 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.
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(Certificate, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.certificate_type = CertificateType() self.certificate_value = CertificateValue() self.certificate_type.read(tstream, kmip_version=kmip_version) self.certificate_value.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream)
381,238
Write the data encoding the Certificate 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.
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): tstream = BytearrayStream() self.certificate_type.write(tstream, kmip_version=kmip_version) self.certificate_value.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(Certificate, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
381,239
Construct a SLUGSConnector. Args: url (string): The base URL for the remote SLUGS instance. Optional, defaults to None. Required for authentication.
def __init__(self, url=None): self._url = None self.users_url = None self.groups_url = None self.url = url
381,259
Construct an Archive response payload struct. Args: unique_identifier (string): The ID of the managed object (e.g., a public key) that was archived. Optional, defaults to None.
def __init__(self, unique_identifier=None): super(ArchiveResponsePayload, self).__init__( enums.Tags.RESPONSE_PAYLOAD ) self._unique_identifier = None self.unique_identifier = unique_identifier
381,266
Write the data encoding the Rekey request 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.
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): local_stream = utils.BytearrayStream() if self._unique_identifier is not None: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._offset is not None: self._offset.write(local_stream, kmip_version=kmip_version) if self._template_attribute is not None: self._template_attribute.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(RekeyRequestPayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
381,280
Construct a ActivateRequestPayload object. Args: unique_identifier (UniqueIdentifier): The UUID of a managed cryptographic object.
def __init__(self, unique_identifier=None): super(ActivateRequestPayload, self).__init__( tag=enums.Tags.REQUEST_PAYLOAD) self.unique_identifier = unique_identifier self.validate()
381,286
Write the data encoding the ActivateRequestPayload 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.
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): tstream = BytearrayStream() # Write the contents of the request payload if self.unique_identifier is not None: self.unique_identifier.write(tstream, kmip_version=kmip_version) # Write the length and value of the request payload self.length = tstream.length() super(ActivateRequestPayload, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
381,287
Set the KMIP version for the client. Args: value (KMIPVersion): A KMIPVersion enumeration Return: None Raises: ValueError: if value is not a KMIPVersion enumeration Example: >>> client.kmip_version = enums.KMIPVersion.KMIP_1_1 >>>
def kmip_version(self, value): if isinstance(value, enums.KMIPVersion): self._kmip_version = value else: raise ValueError("KMIP version must be a KMIPVersion enumeration")
381,291
Check if a profile is supported by the client. Args: conformance_clause (ConformanceClause): authentication_suite (AuthenticationSuite): Returns: bool: True if the profile is supported, False otherwise. Example: >>> client.is_profile_supported( ... ConformanceClause.DISCOVER_VERSIONS, ... AuthenticationSuite.BASIC) True
def is_profile_supported(self, conformance_clause, authentication_suite): return (self.is_conformance_clause_supported(conformance_clause) and self.is_authentication_suite_supported(authentication_suite))
381,292
Send a GetAttributeList request to the server. Args: uid (string): The ID of the managed object with which the retrieved attribute names should be associated. Returns: result (GetAttributeListResult): A structure containing the results of the operation.
def get_attribute_list(self, uid=None): batch_item = self._build_get_attribute_list_batch_item(uid) request = self._build_request_message(None, [batch_item]) response = self._send_and_receive_message(request) results = self._process_batch_items(response) return results[0]
381,303
Create a KmipError exception. Args: status (ResultStatus): An enumeration detailing the result outcome. reason (ResultReason): An enumeration giving the status rationale. message (string): A string containing more information about the error.
def __init__(self, status=enums.ResultStatus.OPERATION_FAILED, reason=enums.ResultReason.GENERAL_FAILURE, message='A general failure occurred.'): super(KmipError, self).__init__(message) self.status = status self.reason = reason
381,352
Create a CryptographicFailure exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(CryptographicFailure, self).__init__( reason=enums.ResultReason.CRYPTOGRAPHIC_FAILURE, message=message )
381,354
Create an EncodingOptionError. Args: message (string): A string containing information about the error.
def __init__(self, message): super(EncodingOptionError, self).__init__( reason=enums.ResultReason.ENCODING_OPTION_ERROR, message=message )
381,355
Create an IllegalOperation exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(IllegalOperation, self).__init__( reason=enums.ResultReason.ILLEGAL_OPERATION, message=message )
381,356
Create an IndexOutOfBounds exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(IndexOutOfBounds, self).__init__( reason=enums.ResultReason.INDEX_OUT_OF_BOUNDS, message=message )
381,357
Create an InvalidField exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(InvalidField, self).__init__( reason=enums.ResultReason.INVALID_FIELD, message=message )
381,358
Create an InvalidMessage exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(InvalidMessage, self).__init__( reason=enums.ResultReason.INVALID_MESSAGE, message=message )
381,359
Create an ItemNotFound exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(ItemNotFound, self).__init__( reason=enums.ResultReason.ITEM_NOT_FOUND, message=message )
381,360
Create a KeyCompressionTypeNotSupported exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(KeyCompressionTypeNotSupported, self).__init__( reason=enums.ResultReason.KEY_COMPRESSION_TYPE_NOT_SUPPORTED, message=message )
381,361
Create a KeyFormatTypeNotSupported exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(KeyFormatTypeNotSupported, self).__init__( reason=enums.ResultReason.KEY_FORMAT_TYPE_NOT_SUPPORTED, message=message )
381,362
Create an OperationNotSupported exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(OperationNotSupported, self).__init__( reason=enums.ResultReason.OPERATION_NOT_SUPPORTED, message=message )
381,363
Create a PermissionDenied exception. Args: message (string): A string containing information about the error.
def __init__(self, message): super(PermissionDenied, self).__init__( reason=enums.ResultReason.PERMISSION_DENIED, message=message )
381,364
Construct the error message and attributes for the KMIP operation failure. Args: status: a ResultStatus enumeration reason: a ResultReason enumeration message: a string providing additional error information
def __init__(self, status, reason, message): msg = "{0}: {1} - {2}".format(status.name, reason.name, message) super(KmipOperationFailure, self).__init__(msg) self.status = status self.reason = reason self.message = message
381,371
Set the KMIP version for the client. Args: value (KMIPVersion): A KMIPVersion enumeration Return: None Raises: ValueError: if value is not a KMIPVersion enumeration Example: >>> client.kmip_version = enums.KMIPVersion.KMIP_1_1 >>>
def kmip_version(self, value): if isinstance(value, enums.KMIPVersion): self.proxy.kmip_version = value else: raise ValueError("KMIP version must be a KMIPVersion enumeration")
381,374
Activate a managed object stored by a KMIP appliance. Args: uid (string): The unique ID of the managed object to activate. Optional, defaults to None. Returns: None Raises: ClientConnectionNotOpen: if the client connection is unusable KmipOperationFailure: if the operation result is a failure TypeError: if the input argument is invalid
def activate(self, uid=None): # Check input if uid is not None: if not isinstance(uid, six.string_types): raise TypeError("uid must be a string") # Activate the managed object and handle the results result = self.proxy.activate(uid) status = result.result_status.value if status == enums.ResultStatus.SUCCESS: return else: reason = result.result_reason.value message = result.result_message.value raise exceptions.KmipOperationFailure(status, reason, message)
381,386
Build a CryptographicParameters struct from a dictionary. Args: value (dict): A dictionary containing the key/value pairs for a CryptographicParameters struct. Returns: None: if value is None CryptographicParameters: a CryptographicParameters struct Raises: TypeError: if the input argument is invalid
def _build_cryptographic_parameters(self, value): if value is None: return None elif not isinstance(value, dict): raise TypeError("Cryptographic parameters must be a dictionary.") cryptographic_parameters = CryptographicParameters( block_cipher_mode=value.get('block_cipher_mode'), padding_method=value.get('padding_method'), hashing_algorithm=value.get('hashing_algorithm'), key_role_type=value.get('key_role_type'), digital_signature_algorithm=value.get( 'digital_signature_algorithm' ), cryptographic_algorithm=value.get('cryptographic_algorithm'), random_iv=value.get('random_iv'), iv_length=value.get('iv_length'), tag_length=value.get('tag_length'), fixed_field_length=value.get('fixed_field_length'), invocation_field_length=value.get('invocation_field_length'), counter_length=value.get('counter_length'), initial_counter_value=value.get('initial_counter_value') ) return cryptographic_parameters
381,392
Build an EncryptionKeyInformation struct from a dictionary. Args: value (dict): A dictionary containing the key/value pairs for a EncryptionKeyInformation struct. Returns: EncryptionKeyInformation: an EncryptionKeyInformation struct Raises: TypeError: if the input argument is invalid
def _build_encryption_key_information(self, value): if value is None: return None if not isinstance(value, dict): raise TypeError("Encryption key information must be a dictionary.") cryptographic_parameters = value.get('cryptographic_parameters') if cryptographic_parameters: cryptographic_parameters = self._build_cryptographic_parameters( cryptographic_parameters ) encryption_key_information = cobjects.EncryptionKeyInformation( unique_identifier=value.get('unique_identifier'), cryptographic_parameters=cryptographic_parameters ) return encryption_key_information
381,393
Build an MACSignatureKeyInformation struct from a dictionary. Args: value (dict): A dictionary containing the key/value pairs for a MACSignatureKeyInformation struct. Returns: MACSignatureInformation: a MACSignatureKeyInformation struct Raises: TypeError: if the input argument is invalid
def _build_mac_signature_key_information(self, value): if value is None: return None if not isinstance(value, dict): raise TypeError( "MAC/signature key information must be a dictionary." ) cryptographic_parameters = value.get('cryptographic_parameters') if cryptographic_parameters: cryptographic_parameters = self._build_cryptographic_parameters( cryptographic_parameters ) mac_signature_key_information = cobjects.MACSignatureKeyInformation( unique_identifier=value.get('unique_identifier'), cryptographic_parameters=cryptographic_parameters ) return mac_signature_key_information
381,394
Build a KeyWrappingSpecification struct from a dictionary. Args: value (dict): A dictionary containing the key/value pairs for a KeyWrappingSpecification struct. Returns: KeyWrappingSpecification: a KeyWrappingSpecification struct Raises: TypeError: if the input argument is invalid
def _build_key_wrapping_specification(self, value): if value is None: return None if not isinstance(value, dict): raise TypeError("Key wrapping specification must be a dictionary.") encryption_key_info = self._build_encryption_key_information( value.get('encryption_key_information') ) mac_signature_key_info = self._build_mac_signature_key_information( value.get('mac_signature_key_information') ) key_wrapping_specification = cobjects.KeyWrappingSpecification( wrapping_method=value.get('wrapping_method'), encryption_key_information=encryption_key_info, mac_signature_key_information=mac_signature_key_info, attribute_names=value.get('attribute_names'), encoding_option=value.get('encoding_option') ) return key_wrapping_specification
381,395
Construct a QueryRequestPayload object. Args: query_functions (list): A list of QueryFunction enumerations.
def __init__(self, query_functions=None): super(QueryRequestPayload, self).__init__(enums.Tags.REQUEST_PAYLOAD) self._query_functions = None self.query_functions = query_functions
381,398
Read the data encoding the QueryResponsePayload object 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.
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): super(QueryResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) operations = [] while(self.is_tag_next(enums.Tags.OPERATION, local_buffer)): operation = primitives.Enumeration( enums.Operation, tag=enums.Tags.OPERATION ) operation.read(local_buffer, kmip_version=kmip_version) operations.append(operation) self._operations = operations object_types = [] while(self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer)): object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) object_type.read(local_buffer, kmip_version=kmip_version) object_types.append(object_type) self._object_types = object_types if self.is_tag_next(enums.Tags.VENDOR_IDENTIFICATION, local_buffer): vendor_identification = primitives.TextString( tag=enums.Tags.VENDOR_IDENTIFICATION ) vendor_identification.read( local_buffer, kmip_version=kmip_version ) self._vendor_identification = vendor_identification if self.is_tag_next(enums.Tags.SERVER_INFORMATION, local_buffer): server_information = misc.ServerInformation() server_information.read( local_buffer, kmip_version=kmip_version ) self._server_information = server_information application_namespaces = [] while(self.is_tag_next( enums.Tags.APPLICATION_NAMESPACE, local_buffer ) ): application_namespace = primitives.TextString( tag=enums.Tags.APPLICATION_NAMESPACE ) application_namespace.read(local_buffer, kmip_version=kmip_version) application_namespaces.append(application_namespace) self._application_namespaces = application_namespaces if kmip_version >= enums.KMIPVersion.KMIP_1_1: extensions_information = [] while(self.is_tag_next( enums.Tags.EXTENSION_INFORMATION, local_buffer ) ): extension_information = objects.ExtensionInformation() extension_information.read( local_buffer, kmip_version=kmip_version ) extensions_information.append(extension_information) self._extension_information = extensions_information if kmip_version >= enums.KMIPVersion.KMIP_1_2: attestation_types = [] while(self.is_tag_next(enums.Tags.ATTESTATION_TYPE, local_buffer)): attestation_type = primitives.Enumeration( enums.AttestationType, tag=enums.Tags.ATTESTATION_TYPE ) attestation_type.read(local_buffer, kmip_version=kmip_version) attestation_types.append(attestation_type) self._attestation_types = attestation_types if kmip_version >= enums.KMIPVersion.KMIP_1_3: rngs_parameters = [] while(self.is_tag_next(enums.Tags.RNG_PARAMETERS, local_buffer)): rng_parameters = objects.RNGParameters() rng_parameters.read(local_buffer, kmip_version=kmip_version) rngs_parameters.append(rng_parameters) self._rng_parameters = rngs_parameters profiles_information = [] while(self.is_tag_next( enums.Tags.PROFILE_INFORMATION, local_buffer ) ): profile_information = objects.ProfileInformation() profile_information.read( local_buffer, kmip_version=kmip_version ) profiles_information.append(profile_information) self._profile_information = profiles_information validations_information = [] while(self.is_tag_next( enums.Tags.VALIDATION_INFORMATION, local_buffer ) ): validation_information = objects.ValidationInformation() validation_information.read( local_buffer, kmip_version=kmip_version ) validations_information.append(validation_information) self._validation_information = validations_information capabilities_information = [] while(self.is_tag_next( enums.Tags.CAPABILITY_INFORMATION, local_buffer ) ): capability_information = objects.CapabilityInformation() capability_information.read( local_buffer, kmip_version=kmip_version ) capabilities_information.append(capability_information) self._capability_information = capabilities_information client_registration_methods = [] while(self.is_tag_next( enums.Tags.CLIENT_REGISTRATION_METHOD, local_buffer ) ): client_registration_method = primitives.Enumeration( enums.ClientRegistrationMethod, tag=enums.Tags.CLIENT_REGISTRATION_METHOD ) client_registration_method.read( local_buffer, kmip_version=kmip_version ) client_registration_methods.append(client_registration_method) self._client_registration_methods = client_registration_methods if kmip_version >= enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.DEFAULTS_INFORMATION, local_buffer): defaults_information = objects.DefaultsInformation() defaults_information.read( local_buffer, kmip_version=kmip_version ) self._defaults_information = defaults_information storage_protection_masks = [] while(self.is_tag_next( enums.Tags.PROTECTION_STORAGE_MASK, local_buffer ) ): storage_protection_mask = primitives.Integer( tag=enums.Tags.PROTECTION_STORAGE_MASK ) storage_protection_mask.read( local_buffer, kmip_version=kmip_version ) storage_protection_masks.append(storage_protection_mask) self._storage_protection_masks = storage_protection_masks self.is_oversized(local_buffer)
381,419
Write the data encoding the QueryResponsePayload object 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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream() if self._operations: for operation in self._operations: operation.write(local_buffer, kmip_version=kmip_version) if self._object_types: for object_type in self._object_types: object_type.write(local_buffer, kmip_version=kmip_version) if self._vendor_identification: self._vendor_identification.write( local_buffer, kmip_version=kmip_version ) if self._server_information: self._server_information.write( local_buffer, kmip_version=kmip_version ) if self._application_namespaces: for application_namespace in self._application_namespaces: application_namespace.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_1_1: if self._extension_information: for extension_information in self._extension_information: extension_information.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_1_2: if self._attestation_types: for attestation_type in self._attestation_types: attestation_type.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_1_3: if self._rng_parameters: for rng_parameters in self._rng_parameters: rng_parameters.write( local_buffer, kmip_version=kmip_version ) if self._profile_information: for profile_information in self._profile_information: profile_information.write( local_buffer, kmip_version=kmip_version ) if self._validation_information: for validation_information in self._validation_information: validation_information.write( local_buffer, kmip_version=kmip_version ) if self._capability_information: for capability_information in self._capability_information: capability_information.write( local_buffer, kmip_version=kmip_version ) if self._client_registration_methods: for client_reg_method in self._client_registration_methods: client_reg_method.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_2_0: if self._defaults_information: self._defaults_information.write( local_buffer, kmip_version=kmip_version ) if self._storage_protection_masks: for storage_protection_mask in self._storage_protection_masks: storage_protection_mask.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(QueryResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
381,420
Construct a GetAttributes request payload. Args: unique_identifier (string): The ID of the managed object with which the retrieved attributes should be associated. Optional, defaults to None. attribute_names: A list of strings identifying the names of the attributes associated with the managed object. Optional, defaults to None.
def __init__(self, unique_identifier=None, attribute_names=None): super(GetAttributesRequestPayload, self).__init__( enums.Tags.REQUEST_PAYLOAD) self._unique_identifier = None self._attribute_names = list() self.unique_identifier = unique_identifier self.attribute_names = attribute_names
381,423
Construct a GetAttributes response payload. Args: unique_identifier (string): The ID of the managed object with which the retrieved attributes should be associated. Optional, defaults to None. attributes (list): A list of attribute structures associated with the managed object. Optional, defaults to None.
def __init__(self, unique_identifier=None, attributes=None): super(GetAttributesResponsePayload, self).__init__( enums.Tags.RESPONSE_PAYLOAD) self._unique_identifier = None self._attributes = list() self.unique_identifier = unique_identifier self.attributes = attributes
381,426
Read the data encoding the GetAttributes 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.
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): super(GetAttributesResponsePayload, 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): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) unique_identifier.read(local_buffer, kmip_version=kmip_version) self.unique_identifier = unique_identifier.value else: raise exceptions.InvalidKmipEncoding( "The GetAttributes response payload encoding is missing the " "unique identifier." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: self._attributes = list() while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer): attribute = objects.Attribute() attribute.read(local_buffer, kmip_version=kmip_version) self._attributes.append(attribute) else: if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attributes = objects.Attributes() attributes.read(local_buffer, kmip_version=kmip_version) # TODO (ph) Add a new utility to avoid using TemplateAttributes temp_attr = objects.convert_attributes_to_template_attribute( attributes ) self._attributes = temp_attr.attributes else: raise exceptions.InvalidKmipEncoding( "The GetAttributes response payload encoding is missing " "the attributes structure." ) self.is_oversized(local_buffer)
381,428
Write the data encoding the GetAttributes 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.
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The GetAttributes response payload is missing the unique " "identifier field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: 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( attributes=self.attributes ) attributes = objects.convert_template_attribute_to_attributes( template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The GetAttributes response payload is missing the " "attributes list." ) self.length = local_buffer.length() super(GetAttributesResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
381,429