示例#1
0
 def test_init_with_args(self):
     """
     Test that a Digest object can be constructed with valid values.
     """
     Digest(hashing_algorithm=HashingAlgorithm(),
            digest_value=DigestValue(),
            key_format_type=KeyFormatType())
示例#2
0
 def test_str_with_data(self):
     """
     Test that the string representation of a Digest object is formatted
     properly when there is internal data.
     """
     data = b'\x00\x01\x02\x03'
     digest_value = DigestValue(data)
     self._test_str(digest_value, str(data))
示例#3
0
    def setUp(self):
        super(TestDigest, self).setUp()

        self.hashing_algorithm_a = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_b = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_c = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_d = HashingAlgorithm(HashingAlgorithmEnum.SHA_1)

        self.digest_value_a = DigestValue(b'')
        self.digest_value_b = DigestValue(
            b'\x6C\x06\x4F\xE0\x51\xAD\xD1\x1E\xDC\x07\x72\x7B\x59\x4E\xB4\x87'
            b'\x11\xDF\x84\x3E\x08\x44\x5B\xBA\x2C\xD7\x86\xBC\x16\xBC\x58'
            b'\xE8')
        self.digest_value_c = DigestValue(
            b'\x11\x11\x0A\x01\xED\x45\x89\xD9\x98\x7C\x9A\xD6\x03\x68\xE2\xB7'
            b'\x62\xF2\xB2\x0C\x00\x94\x6E\x19\x32\xC1\x60\x5A\x18\x17\x2F'
            b'\x55')

        self.key_format_type_a = KeyFormatType(KeyFormatTypeEnum.RAW)
        self.key_format_type_b = KeyFormatType(KeyFormatTypeEnum.RAW)
        self.key_format_type_c = KeyFormatType(KeyFormatTypeEnum.PKCS_1)

        # Encodings obtained from Section 18.1 and 18.2 of the KMIP 1.1 Test
        # Cases document.
        self.encoding_a = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x28\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x00'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00'
            b'\x00'))
        self.encoding_b = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x48\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x20'
            b'\x6C\x06\x4F\xE0\x51\xAD\xD1\x1E\xDC\x07\x72\x7B\x59\x4E\xB4\x87'
            b'\x11\xDF\x84\x3E\x08\x44\x5B\xBA\x2C\xD7\x86\xBC\x16\xBC\x58\xE8'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00'
            b'\x00'))
        self.encoding_c = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x48\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x20'
            b'\x11\x11\x0A\x01\xED\x45\x89\xD9\x98\x7C\x9A\xD6\x03\x68\xE2\xB7'
            b'\x62\xF2\xB2\x0C\x00\x94\x6E\x19\x32\xC1\x60\x5A\x18\x17\x2F\x55'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00'
            b'\x00'))
示例#4
0
    def _test_init(self, value):
        if (isinstance(value, bytes)) or (value is None):
            digest_value = DigestValue(value)

            if value is None:
                value = bytes()

            msg = "expected {0}, observed {1}".format(value,
                                                      digest_value.value)
            self.assertEqual(value, digest_value.value, msg)
        else:
            self.assertRaises(TypeError, DigestValue, value)
示例#5
0
    def _test_create(self, digest, hashing_algorithm, digest_value,
                     key_format_type):
        self.assertIsInstance(digest, Digest)

        expected = HashingAlgorithm(hashing_algorithm)
        observed = digest.hashing_algorithm

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = DigestValue(digest_value)
        observed = digest.digest_value

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = KeyFormatType(key_format_type)
        observed = digest.key_format_type

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
示例#6
0
    def test_repr(self):
        """
        Test that the representation of a Digest object with data is formatted
        properly.
        """
        hashing_algorithm = HashingAlgorithm(HashingAlgorithmEnum.MD5)
        digest_value = DigestValue(b'\x00\x01\x02\x03')
        key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
        digest = Digest(hashing_algorithm=hashing_algorithm,
                        digest_value=digest_value,
                        key_format_type=key_format_type)

        hashing_algorithm = "hashing_algorithm={0}".format(
            repr(hashing_algorithm))
        digest_value = "digest_value={0}".format(repr(digest_value))
        key_format_type = "key_format_type={0}".format(repr(key_format_type))

        expected = "Digest({0}, {1}, {2})".format(hashing_algorithm,
                                                  digest_value,
                                                  key_format_type)
        observed = repr(digest)

        msg = "expected:\n{0},\nobserved:\n{1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)