コード例 #1
0
    def test_equal_on_equal_and_empty(self):
        """
        Test that the equality operator returns True when comparing two
        BigIntegers.
        """
        a = primitives.BigInteger()
        b = primitives.BigInteger()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
コード例 #2
0
    def test_equal_on_not_equal(self):
        """
        Test that the equality operator returns False when comparing two
        BigIntegers with different values.
        """
        a = primitives.BigInteger(1)
        b = primitives.BigInteger(2)

        self.assertFalse(a == b)
        self.assertFalse(b == a)
コード例 #3
0
    def test_not_equal_on_not_equal(self):
        """
        Test that the inequality operator returns True when comparing two
        BigIntegers with different values.
        """
        a = primitives.BigInteger(1)
        b = primitives.BigInteger(2)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #4
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing
        two BigIntegers with the same values.
        """
        a = primitives.BigInteger(1)
        b = primitives.BigInteger(1)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #5
0
    def test_not_equal_on_equal_and_empty(self):
        """
        Test that the inequality operator returns False when comparing
        two BigIntegers.
        """
        a = primitives.BigInteger()
        b = primitives.BigInteger()

        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #6
0
 def test_read_zero(self):
     """
     Test that a BigInteger representing the value 0 can be read from a
     byte stream.
     """
     big_int = primitives.BigInteger()
     big_int.read(self.encoding_zero)
     self.assertEqual(0, big_int.value)
コード例 #7
0
 def test_read_on_invalid_length(self):
     """
     Test that an InvalidPrimitiveLength exception is thrown when attempting
     to decode a BigInteger with an invalid length.
     """
     big_int = primitives.BigInteger()
     self.assertRaises(exceptions.InvalidPrimitiveLength, big_int.read,
                       self.encoding_bad_length)
コード例 #8
0
 def test_read_negative(self):
     """
     Test that a BigInteger representing a negative value can be read from
     a byte stream.
     """
     big_int = primitives.BigInteger()
     big_int.read(self.encoding_negative)
     self.assertEqual(self.value_negative, big_int.value)
コード例 #9
0
 def test_repr(self):
     """
     Test that the representation of a BigInteger is formatted properly.
     """
     long_int = primitives.BigInteger()
     value = "value={0}".format(long_int.value)
     tag = "tag={0}".format(long_int.tag)
     self.assertEqual("BigInteger({0}, {1})".format(value, tag),
                      repr(long_int))
コード例 #10
0
 def test_write_negative(self):
     """
     Test that a BigInteger representing a negative value can be written to
     a byte stream.
     """
     stream = utils.BytearrayStream()
     big_int = primitives.BigInteger(self.value_negative)
     big_int.write(stream)
     self.assertEqual(self.encoding_negative, stream)
コード例 #11
0
 def test_write_zero(self):
     """
     Test that a BigInteger representing the value 0 can be read written to
     a byte stream.
     """
     stream = utils.BytearrayStream()
     big_int = primitives.BigInteger()
     big_int.write(stream)
     self.assertEqual(self.encoding_zero, stream)
コード例 #12
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing a
        BigInteger to a non-BigInteger object.
        """
        a = primitives.BigInteger()
        b = 'invalid'

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #13
0
    def test_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns False when comparing a
        BigInteger to a non-BigInteger object.
        """
        a = primitives.BigInteger()
        b = 'invalid'

        self.assertFalse(a == b)
        self.assertFalse(b == a)
コード例 #14
0
ファイル: secrets.py プロジェクト: xxgoracle/PyKMIP
 def prime_field_size(self, value):
     if value is None:
         self._prime_field_size = None
     elif isinstance(value, six.integer_types):
         self._prime_field_size = primitives.BigInteger(
             value=value,
             tag=enums.Tags.PRIME_FIELD_SIZE
         )
     else:
         raise TypeError("The prime field size must be an integer.")
コード例 #15
0
 def test_init_unset(self):
     """
     Test that a BigInteger can be instantiated with no input.
     """
     big_int = primitives.BigInteger()
     self.assertEqual(0, big_int.value)
コード例 #16
0
 def test_init(self):
     """
     Test that a BigInteger can be instantiated.
     """
     big_int = primitives.BigInteger(1)
     self.assertEqual(1, big_int.value)
コード例 #17
0
 def test_str(self):
     """
     Test that the string representation of a BigInteger is formatted
     properly.
     """
     self.assertEqual("0", str(primitives.BigInteger()))
コード例 #18
0
ファイル: secrets.py プロジェクト: xxgoracle/PyKMIP
    def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the SplitKey object and decode it.

        Args:
            input_buffer (stream): A data stream containing the encoded object
                data, supporting a read method; usually a BytearrayStream
                object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(SplitKey, self).read(input_buffer, kmip_version=kmip_version)
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.SPLIT_KEY_PARTS, local_buffer):
            self._split_key_parts = primitives.Integer(
                tag=enums.Tags.SPLIT_KEY_PARTS
            )
            self._split_key_parts.read(local_buffer, kmip_version=kmip_version)
        else:
            raise exceptions.InvalidKmipEncoding(
                "The SplitKey encoding is missing the SplitKeyParts field."
            )

        if self.is_tag_next(enums.Tags.KEY_PART_IDENTIFIER, local_buffer):
            self._key_part_identifier = primitives.Integer(
                tag=enums.Tags.KEY_PART_IDENTIFIER
            )
            self._key_part_identifier.read(
                local_buffer,
                kmip_version=kmip_version
            )
        else:
            raise exceptions.InvalidKmipEncoding(
                "The SplitKey encoding is missing the KeyPartIdentifier field."
            )

        if self.is_tag_next(enums.Tags.SPLIT_KEY_THRESHOLD, local_buffer):
            self._split_key_threshold = primitives.Integer(
                tag=enums.Tags.SPLIT_KEY_THRESHOLD
            )
            self._split_key_threshold.read(
                local_buffer,
                kmip_version=kmip_version
            )
        else:
            raise exceptions.InvalidKmipEncoding(
                "The SplitKey encoding is missing the SplitKeyThreshold field."
            )

        if self.is_tag_next(enums.Tags.SPLIT_KEY_METHOD, local_buffer):
            self._split_key_method = primitives.Enumeration(
                enums.SplitKeyMethod,
                tag=enums.Tags.SPLIT_KEY_METHOD
            )
            self._split_key_method.read(
                local_buffer,
                kmip_version=kmip_version
            )
        else:
            raise exceptions.InvalidKmipEncoding(
                "The SplitKey encoding is missing the SplitKeyMethod field."
            )

        if self.is_tag_next(enums.Tags.PRIME_FIELD_SIZE, local_buffer):
            self._prime_field_size = primitives.BigInteger(
                tag=enums.Tags.PRIME_FIELD_SIZE
            )
            self._prime_field_size.read(
                local_buffer,
                kmip_version=kmip_version
            )
        else:
            corner_case = enums.SplitKeyMethod.POLYNOMIAL_SHARING_PRIME_FIELD
            if self.split_key_method == corner_case:
                raise exceptions.InvalidKmipEncoding(
                    "The SplitKey encoding is missing the PrimeFieldSize "
                    "field. This field is required when the SplitKeyMethod is "
                    "PolynomialSharingPrimeField."
                )

        if self.is_tag_next(enums.Tags.KEY_BLOCK, local_buffer):
            self._key_block = objects.KeyBlock()
            self._key_block.read(local_buffer, kmip_version=kmip_version)
        else:
            raise exceptions.InvalidKmipEncoding(
                "The SplitKey encoding is missing the KeyBlock field."
            )

        self.is_oversized(local_buffer)
コード例 #19
0
 def test_init_negative(self):
     """
     Test that a BigInteger can be instantiated with negative input.
     """
     big_int = primitives.BigInteger(self.value_negative)
     self.assertEqual(self.value_negative, big_int.value)