#!/usr/bin/env python # # Simple test cases for a Python version of the yubikey_crc16() function in ykcrc.c. # import struct import unittest import yubico.yubico_util as yubico_util from yubico.yubico_util import crc16 CRC_OK_RESIDUAL=0xf0b8 class TestCRC(unittest.TestCase): def test_first(self): """ Test CRC16 trivial case """ buffer = b'\x01\x02\x03\x04' crc = crc16(buffer) self.assertEqual(crc, 0xc66e) return buffer,crc def test_second(self): """ Test CRC16 residual calculation """ buffer,crc = self.test_first() # Append 1st complement for a "self-verifying" block - # from example in Yubikey low level interface crc_inv = 0xffff - crc buffer += struct.pack('