本文整理汇总了Python中authenticator.HOTP.generate_hmac方法的典型用法代码示例。如果您正苦于以下问题:Python HOTP.generate_hmac方法的具体用法?Python HOTP.generate_hmac怎么用?Python HOTP.generate_hmac使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类authenticator.HOTP
的用法示例。
在下文中一共展示了HOTP.generate_hmac方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_generate_hmac_secret_not_byte_string
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import generate_hmac [as 别名]
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])
示例2: test_generate_hmac_counter_not_byte_string
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import generate_hmac [as 别名]
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")
示例3: test_generate_hmac_bad_counter
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import generate_hmac [as 别名]
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"))
示例4: test_generate_hmac
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import generate_hmac [as 别名]
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)
示例5: test_hmac_from_counter
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import generate_hmac [as 别名]
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)