def test_generate_hmac_secret_not_byte_string(self): """Test Otp.generate_hmac(). Check that a counter that is other than a byte string. """ cut = HOTP() # If the counter byte string is less than 8 bytes # with self.assertRaises(TypeError): cut.generate_hmac("1234567890", self.expected[1][0])
def test_generate_hmac_counter_not_byte_string(self): """Test Otp.generate_hmac(). Check that a counter that is other than a byte string. """ cut = HOTP() # If the counter byte string is less than 8 bytes # with self.assertRaises(TypeError): cut.generate_hmac(self.secret, "1234")
def test_generate_hmac_bad_counter(self): """Test Otp.generate_hmac(). Check that a counter that is other than 8 bytes raises an error. """ cut = HOTP() # If the counter byte string is less than 8 bytes # with self.assertRaises(ValueError): cut.generate_hmac(self.secret, bytes.fromhex("1234")) # If the counter byte string is more than 8 bytes # with self.assertRaises(ValueError): cut.generate_hmac(self.secret, bytes.fromhex("12345678901234567890"))
def test_generate_hmac_bad_counter(self): """Test Otp.generate_hmac(). Check that a counter that is other than 8 bytes raises an error. """ cut = HOTP() # If the counter byte string is less than 8 bytes # with self.assertRaises(ValueError): cut.generate_hmac(self.secret, bytes.fromhex("1234")) # If the counter byte string is more than 8 bytes # with self.assertRaises(ValueError): cut.generate_hmac( self.secret, bytes.fromhex("12345678901234567890"))
def test_generate_hmac(self): """Test Otp.generate_hmac(). Check that the RFC4226 test cases work for generate_hmac(). """ cut = HOTP() for i in range(0, 10): hmac = cut.generate_hmac(self.secret, self.expected[i][0]) self.assertEqual(self.expected[i][1], hmac)
def test_hmac_from_counter(self): """Test Otp.generate_hmac(). Check that expected HMAC-SHA-1 digest values are produced. """ cut = HOTP() for i in range(0, 10): counter = cut.num_to_counter(i) actual_hmac = cut.generate_hmac(self.secret, counter) self.assertEqual(self.expected[i][1], actual_hmac)