kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
        """
        Read the data encoding the RNGParameters structure and decode it
        into its constituent parts.

        Args:
            input_buffer (stream): A data stream containing encoded object
                data, supporting a read method; usually a BytearrayStream
                object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            InvalidKmipEncoding: Raised if the RNG algorithm is missing from
                the encoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the RNGParameters structure.
        """
        if kmip_version < enums.KMIPVersion.KMIP_1_3:
            raise exceptions.VersionNotSupported(
                "KMIP {} does not support the RNGParameters object.".format(
                    kmip_version.value
                )
            )

        super(RNGParameters, self).read(
            input_buffer,
            kmip_version=kmip_version
        )
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.RNG_ALGORITHM, local_buffer):
            rng_algorithm = primitives.Enumeration(
                enums.RNGAlgorithm,
                tag=enums.Tags.RNG_ALGORITHM
            )
            rng_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._rng_algorithm = rng_algorithm
        else:
            raise exceptions.InvalidKmipEncoding(
                "The RNGParameters encoding is missing the RNG algorithm."
            )

        if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_ALGORITHM, local_buffer):
            cryptographic_algorithm = primitives.Enumeration(
                enums.CryptographicAlgorithm,
                tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM
            )
            cryptographic_algorithm.read(
                local_buffer,
                kmip_version=kmip_version
            )
            self._cryptographic_algorithm = cryptographic_algorithm

        if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_LENGTH, local_buffer):
            cryptographic_length = primitives.Integer(
                tag=enums.Tags.CRYPTOGRAPHIC_LENGTH
            )
            cryptographic_length.read(local_buffer, kmip_version=kmip_version)
            self._cryptographic_length = cryptographic_length

        if self.is_tag_next(enums.Tags.HASHING_ALGORITHM, local_buffer):
            hashing_algorithm = primitives.Enumeration(
                enums.HashingAlgorithm,
                tag=enums.Tags.HASHING_ALGORITHM
            )
            hashing_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._hashing_algorithm = hashing_algorithm

        if self.is_tag_next(enums.Tags.DRBG_ALGORITHM, local_buffer):
            drbg_algorithm = primitives.Enumeration(
                enums.DRBGAlgorithm,
                tag=enums.Tags.DRBG_ALGORITHM
            )
            drbg_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._drbg_algorithm = drbg_algorithm

        if self.is_tag_next(enums.Tags.RECOMMENDED_CURVE, local_buffer):
            recommended_curve = primitives.Enumeration(
                enums.RecommendedCurve,
                tag=enums.Tags.RECOMMENDED_CURVE
            )
            recommended_curve.read(local_buffer, kmip_version=kmip_version)
            self._recommended_curve = recommended_curve

        if self.is_tag_next(enums.Tags.FIPS186_VARIATION, local_buffer):
            fips186_variation = primitives.Enumeration(
                enums.FIPS186Variation,
                tag=enums.Tags.FIPS186_VARIATION
            )
            fips186_variation.read(local_buffer, kmip_version=kmip_version)
            self._fips186_variation = fips186_variation

        if self.is_tag_next(enums.Tags.PREDICTION_RESISTANCE, local_buffer):
            prediction_resistance = primitives.Boolean(
                tag=enums.Tags.PREDICTION_RESISTANCE
            )
            prediction_resistance.read(
                local_buffer,
                kmip_version=kmip_version
            )
            self._prediction_resistance = prediction_resistance

        self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
        """
        Read the data encoding the RNGParameters structure and decode it
        into its constituent parts.

        Args:
            input_buffer (stream): A data stream containing encoded object
                data, supporting a read method; usually a BytearrayStream
                object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            InvalidKmipEncoding: Raised if the RNG algorithm is missing from
                the encoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the RNGParameters structure.
        """
        if kmip_version < enums.KMIPVersion.KMIP_1_3:
            raise exceptions.VersionNotSupported(
                "KMIP {} does not support the RNGParameters object.".format(
                    kmip_version.value
                )
            )

        super(RNGParameters, self).read(
            input_buffer,
            kmip_version=kmip_version
        )
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.RNG_ALGORITHM, local_buffer):
            rng_algorithm = primitives.Enumeration(
                enums.RNGAlgorithm,
                tag=enums.Tags.RNG_ALGORITHM
            )
            rng_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._rng_algorithm = rng_algorithm
        else:
            raise exceptions.InvalidKmipEncoding(
                "The RNGParameters encoding is missing the RNG algorithm."
            )

        if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_ALGORITHM, local_buffer):
            cryptographic_algorithm = primitives.Enumeration(
                enums.CryptographicAlgorithm,
                tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM
            )
            cryptographic_algorithm.read(
                local_buffer,
                kmip_version=kmip_version
            )
            self._cryptographic_algorithm = cryptographic_algorithm

        if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_LENGTH, local_buffer):
            cryptographic_length = primitives.Integer(
                tag=enums.Tags.CRYPTOGRAPHIC_LENGTH
            )
            cryptographic_length.read(local_buffer, kmip_version=kmip_version)
            self._cryptographic_length = cryptographic_length

        if self.is_tag_next(enums.Tags.HASHING_ALGORITHM, local_buffer):
            hashing_algorithm = primitives.Enumeration(
                enums.HashingAlgorithm,
                tag=enums.Tags.HASHING_ALGORITHM
            )
            hashing_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._hashing_algorithm = hashing_algorithm

        if self.is_tag_next(enums.Tags.DRBG_ALGORITHM, local_buffer):
            drbg_algorithm = primitives.Enumeration(
                enums.DRBGAlgorithm,
                tag=enums.Tags.DRBG_ALGORITHM
            )
            drbg_algorithm.read(local_buffer, kmip_version=kmip_version)
            self._drbg_algorithm = drbg_algorithm

        if self.is_tag_next(enums.Tags.RECOMMENDED_CURVE, local_buffer):
            recommended_curve = primitives.Enumeration(
                enums.RecommendedCurve,
                tag=enums.Tags.RECOMMENDED_CURVE
            )
            recommended_curve.read(local_buffer, kmip_version=kmip_version)
            self._recommended_curve = recommended_curve

        if self.is_tag_next(enums.Tags.FIPS186_VARIATION, local_buffer):
            fips186_variation = primitives.Enumeration(
                enums.FIPS186Variation,
                tag=enums.Tags.FIPS186_VARIATION
            )
            fips186_variation.read(local_buffer, kmip_version=kmip_version)
            self._fips186_variation = fips186_variation

        if self.is_tag_next(enums.Tags.PREDICTION_RESISTANCE, local_buffer):
            prediction_resistance = primitives.Boolean(
                tag=enums.Tags.PREDICTION_RESISTANCE
            )
            prediction_resistance.read(
                local_buffer,
                kmip_version=kmip_version
            )
            self._prediction_resistance = prediction_resistance

        self.is_oversized(local_buffer)
Read the data encoding the RNGParameters structure and decode it
        into its constituent parts.

        Args:
            input_buffer (stream): A data stream containing encoded object
                data, supporting a read method; usually a BytearrayStream
                object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            InvalidKmipEncoding: Raised if the RNG algorithm is missing from
                the encoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the RNGParameters structure.