Пример #1
0
    def test_simple_crc32_class(self):
        """Verify the CRC class when not using xorOut"""
        crc = Crc(g32)

        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0xFFFFFFFF
xorOut   = 0x00000000
crcValue = 0xFFFFFFFF'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(crc.digest(), '\xff\xff\xff\xff')
        self.assertEqual(crc.hexdigest(), 'FFFFFFFF')

        crc.update(self.msg)
        self.assertEqual(crc.crcValue, 0xF7B400A7L)
        self.assertEqual(crc.digest(), '\xf7\xb4\x00\xa7')
        self.assertEqual(crc.hexdigest(), 'F7B400A7')

        # Verify the .copy() method
        x = crc.copy()
        self.assertTrue(x is not crc)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0xFFFFFFFF
xorOut   = 0x00000000
crcValue = 0xF7B400A7'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(str(x), str_rep)
Пример #2
0
    def test_simple_crc32_class(self):
        """Verify the CRC class when not using xorOut"""
        crc = Crc(g32)

        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0xFFFFFFFF
xorOut   = 0x00000000
crcValue = 0xFFFFFFFF'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(crc.digest(), '\xff\xff\xff\xff')
        self.assertEqual(crc.hexdigest(), 'FFFFFFFF')

        crc.update(self.msg)
        self.assertEqual(crc.crcValue, 0xF7B400A7L)
        self.assertEqual(crc.digest(), '\xf7\xb4\x00\xa7')
        self.assertEqual(crc.hexdigest(), 'F7B400A7')

        # Verify the .copy() method
        x = crc.copy()
        self.assertTrue(x is not crc)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0xFFFFFFFF
xorOut   = 0x00000000
crcValue = 0xF7B400A7'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(str(x), str_rep)
Пример #3
0
    def test_full_crc32_class(self):
        """Verify the CRC class when using xorOut"""

        crc = Crc(g32, initCrc=0, xorOut=~0L)

        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x00000000'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(crc.digest(), '\x00\x00\x00\x00')
        self.assertEqual(crc.hexdigest(), '00000000')

        crc.update(self.msg)
        self.assertEqual(crc.crcValue, 0x84BFF58L)
        self.assertEqual(crc.digest(), '\x08\x4b\xff\x58')
        self.assertEqual(crc.hexdigest(), '084BFF58')

        # Verify the .copy() method
        x = crc.copy()
        self.assertTrue(x is not crc)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x084BFF58'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(str(x), str_rep)

        # Verify the .new() method
        y = crc.new()
        self.assertTrue(y is not crc)
        self.assertTrue(y is not x)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x00000000'''
        self.assertEqual(str(y), str_rep)
Пример #4
0
    def test_full_crc32_class(self):
        """Verify the CRC class when using xorOut"""

        crc = Crc(g32, initCrc=0, xorOut= ~0L)

        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x00000000'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(crc.digest(), '\x00\x00\x00\x00')
        self.assertEqual(crc.hexdigest(), '00000000')

        crc.update(self.msg)
        self.assertEqual(crc.crcValue, 0x84BFF58L)
        self.assertEqual(crc.digest(), '\x08\x4b\xff\x58')
        self.assertEqual(crc.hexdigest(), '084BFF58')

        # Verify the .copy() method
        x = crc.copy()
        self.assertTrue(x is not crc)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x084BFF58'''
        self.assertEqual(str(crc), str_rep)
        self.assertEqual(str(x), str_rep)

        # Verify the .new() method
        y = crc.new()
        self.assertTrue(y is not crc)
        self.assertTrue(y is not x)
        str_rep = \
'''poly = 0x104C11DB7
reverse = True
initCrc  = 0x00000000
xorOut   = 0xFFFFFFFF
crcValue = 0x00000000'''
        self.assertEqual(str(y), str_rep)