def test_hash_from_hmac_not_20bytes(self): """Test Otp.hash_from_hmac(). Check that HMAC length validation is performed. """ cut = HOTP() hmac = bytes.fromhex("ff0102030405060708090a0b0c0d0e0f101112") with self.assertRaises(ValueError): cut.hash_from_hmac(hmac)
def test_hash_from_hmac_not_byte_string(self): """Test Otp.hash_from_hmac(). Check that HMAC type (byte string) validation is performed. """ cut = HOTP() hmac = bytearray.fromhex("ff0102030405060708090a0b0c0d0e0f101112f0") with self.assertRaises(TypeError): cut.hash_from_hmac(hmac)
def test_hash_from_hmac_clear_high_bit(self): """Test Otp.hash_from_hmac(). Check that the high order bit is cleared in the truncated hash. """ cut = HOTP() hmac = bytes.fromhex("ff0102030405060708090a0b0c0d0e0f101112f0") expected = bytes.fromhex("7f010203") hash = cut.hash_from_hmac(hmac) self.assertEqual(expected, hash)
def test_hash_from_hmac(self): """Test Otp.hash_from_hmac(). Check that expected truncated hash values are produced. """ cut = HOTP() for i in range(0, 10): hash = cut.hash_from_hmac(self.expected[i][1]) self.assertEqual(self.expected[i][2], hash) return