Exemple #1
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing
        two LongIntegers with the same values.
        """
        a = primitives.LongInteger(1)
        b = primitives.LongInteger(1)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Exemple #2
0
    def test_equal_on_not_equal(self):
        """
        Test that the equality operator returns False when comparing two
        LongIntegers with different values.
        """
        a = primitives.LongInteger(1)
        b = primitives.LongInteger(2)

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Exemple #3
0
    def test_not_equal_on_equal_and_empty(self):
        """
        Test that the inequality operator returns False when comparing
        two LongIntegers.
        """
        a = primitives.LongInteger()
        b = primitives.LongInteger()

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Exemple #4
0
    def test_not_equal_on_not_equal(self):
        """
        Test that the inequality operator returns True when comparing two
        LongIntegers with different values.
        """
        a = primitives.LongInteger(1)
        b = primitives.LongInteger(2)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemple #5
0
    def test_equal_on_equal_and_empty(self):
        """
        Test that the equality operator returns True when comparing two
        LongIntegers.
        """
        a = primitives.LongInteger()
        b = primitives.LongInteger()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Exemple #6
0
    def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the GetUsageAllocation request payload and
        decode it into its constituent parts.

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

        Raises:
            ValueError: Raised if the data attribute is missing from the
                encoded payload.
        """
        super(GetUsageAllocationRequestPayload,
              self).read(input_stream, kmip_version=kmip_version)
        local_stream = utils.BytearrayStream(input_stream.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
            self._unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER)
            self._unique_identifier.read(local_stream,
                                         kmip_version=kmip_version)
        if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream):
            self._usage_limits_count = primitives.LongInteger(
                tag=enums.Tags.USAGE_LIMITS_COUNT)
            self._usage_limits_count.read(local_stream,
                                          kmip_version=kmip_version)

        self.is_oversized(local_stream)
Exemple #7
0
    def read(self, input_stream):
        """
        Read the data encoding the Check response payload and decode it into
        its constituent parts.

        Args:
            input_stream (stream): A data stream containing encoded object
                data, supporting a read method; usually a BytearrayStream
                object.

        Raises:
            ValueError: Raised if the data attribute is missing from the
                encoded payload.
        """
        super(CheckResponsePayload, self).read(input_stream)
        local_stream = utils.BytearrayStream(input_stream.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
            self._unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER)
            self._unique_identifier.read(local_stream)
        if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream):
            self._usage_limits_count = primitives.LongInteger(
                tag=enums.Tags.USAGE_LIMITS_COUNT)
            self._usage_limits_count.read(local_stream)
        if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_USAGE_MASK, local_stream):
            self._cryptographic_usage_mask = primitives.Integer(
                tag=enums.Tags.CRYPTOGRAPHIC_USAGE_MASK)
            self._cryptographic_usage_mask.read(local_stream)
        if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream):
            self._lease_time = primitives.Interval(tag=enums.Tags.LEASE_TIME)
            self._lease_time.read(local_stream)

        self.is_oversized(local_stream)
Exemple #8
0
 def usage_limits_count(self, value):
     if value is None:
         self._usage_limits_count = None
     elif isinstance(value, six.integer_types):
         self._usage_limits_count = primitives.LongInteger(
             value=value, tag=enums.Tags.USAGE_LIMITS_COUNT)
     else:
         raise TypeError("Usage limits count must be an integer.")
Exemple #9
0
 def test_repr(self):
     """
     Test that the representation of a LongInteger is formatted properly.
     """
     long_int = primitives.LongInteger()
     value = "value={0}".format(long_int.value)
     tag = "tag={0}".format(long_int.tag)
     self.assertEqual("LongInteger({0}, {1})".format(value, tag),
                      repr(long_int))
Exemple #10
0
    def test_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns False when comparing a
        LongInteger to a non-LongInteger object.
        """
        a = primitives.LongInteger()
        b = 'invalid'

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Exemple #11
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing a
        LongInteger to a non-LongInteger object.
        """
        a = primitives.LongInteger()
        b = 'invalid'

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemple #12
0
 def test_read_zero(self):
     """
     Test that a LongInteger representing the value 0 can be read from a
     byte stream.
     """
     encoding = (
         b'\x42\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00'
         b'\x00')
     stream = utils.BytearrayStream(encoding)
     long_int = primitives.LongInteger()
     long_int.read(stream)
     self.assertEqual(0, long_int.value)
Exemple #13
0
 def test_read_max_max(self):
     """
     Test that a LongInteger representing the maximum positive value can be
     read from a byte stream.
     """
     encoding = (
         b'\x42\x00\x00\x03\x00\x00\x00\x08\x7f\xff\xff\xff\xff\xff\xff'
         b'\xff')
     stream = utils.BytearrayStream(encoding)
     long_int = primitives.LongInteger()
     long_int.read(stream)
     self.assertEqual(primitives.LongInteger.MAX, long_int.value)
Exemple #14
0
 def test_read_min_min(self):
     """
     Test that a LongInteger representing the minimum negative value can be
     read from a byte stream.
     """
     encoding = (
         b'\x42\x00\x00\x03\x00\x00\x00\x08\x80\x00\x00\x00\x00\x00\x00'
         b'\x00')
     stream = utils.BytearrayStream(encoding)
     long_int = primitives.LongInteger(primitives.LongInteger.MIN)
     long_int.read(stream)
     self.assertEqual(primitives.LongInteger.MIN, long_int.value)
Exemple #15
0
    def test_read_on_invalid_length(self):
        """
        Test that an InvalidPrimitiveLength exception is thrown when attempting
        to decode a LongInteger with an invalid length.
        """
        encoding = (
            b'\x42\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00')
        stream = utils.BytearrayStream(encoding)
        long_int = primitives.LongInteger()

        self.assertRaises(exceptions.InvalidPrimitiveLength, long_int.read,
                          stream)
Exemple #16
0
    def test_write_min_min(self):
        """
        Test that a LongInteger representing the minimum negative value can be
        written to a byte stream.
        """
        encoding = (
            b'\x42\x00\x00\x03\x00\x00\x00\x08\x80\x00\x00\x00\x00\x00\x00'
            b'\x00')
        stream = utils.BytearrayStream()
        long_int = primitives.LongInteger(primitives.LongInteger.MIN)
        long_int.write(stream)

        result = stream.read()
        self.assertEqual(len(encoding), len(result))
        self.assertEqual(encoding, result)
Exemple #17
0
 def test_validate_on_valid_unset(self):
     """
     Test that a LongInteger with no preset value can be validated.
     """
     long_int = primitives.LongInteger()
     long_int.validate()
Exemple #18
0
 def test_validate_on_valid(self):
     """
     Test that a LongInteger can be validated on good input.
     """
     long_int = primitives.LongInteger(1)
     long_int.validate()
Exemple #19
0
 def test_init_on_min(self):
     """
     Test that a LongInteger can be instantiated with the minimum possible
     signed 64-bit value.
     """
     primitives.LongInteger(primitives.LongInteger.MIN)
Exemple #20
0
 def test_init_unset(self):
     """
     Test that a LongInteger can be instantiated with no input.
     """
     long_int = primitives.LongInteger()
     self.assertEqual(0, long_int.value)
Exemple #21
0
 def test_init(self):
     """
     Test that a LongInteger can be instantiated.
     """
     long_int = primitives.LongInteger(1)
     self.assertEqual(1, long_int.value)
Exemple #22
0
 def test_str(self):
     """
     Test that the string representation of a LongInteger is formatted
     properly.
     """
     self.assertEqual("0", str(primitives.LongInteger()))