本文整理汇总了Python中authenticator.HOTP.convert_base32_secret_key方法的典型用法代码示例。如果您正苦于以下问题:Python HOTP.convert_base32_secret_key方法的具体用法?Python HOTP.convert_base32_secret_key怎么用?Python HOTP.convert_base32_secret_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类authenticator.HOTP
的用法示例。
在下文中一共展示了HOTP.convert_base32_secret_key方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_convert_base32_bad_chars
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_bad_chars(self):
"""Test Otp.convert_base32_secret_key().
Check that an input base32 encoded string that is not encoded correctly
throws the expected exception.
"""
cut = HOTP()
# First be certain the method works with a correct base32-encoded
# input string
#
in_string = "ABCDEFGH"
cut.convert_base32_secret_key(in_string)
# Then check that it throws the expected exception with an
# incorrectly coded input string.
#
# lower case not acceptable
in_string = "abcdefgh"
with self.assertRaises(ValueError):
cut.convert_base32_secret_key(in_string)
# numbers outside 2-7 not acceptable
in_string = "ABCDEFG1"
with self.assertRaises(ValueError):
cut.convert_base32_secret_key(in_string)
# padding character elsewhere than end of string
in_string = "ABCD=FGH"
with self.assertRaises(ValueError):
cut.convert_base32_secret_key(in_string)
示例2: test_convert_base32_too_long
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_too_long(self):
"""Test Otp.convert_base32_secret_key().
Check that an input base32 encoded string that is not multiples of 8
characters in length (too long) throws the expected exception.
"""
cut = HOTP()
# First be certain the method works with a correct base32-encoded
# input string
#
in_string = "ABCDEFGH"
cut.convert_base32_secret_key(in_string)
# Then check that it throws the expected exception with an
# incorrectly sized input string.
#
in_string = "ABCDEFGHA"
with self.assertRaises(ValueError):
cut.convert_base32_secret_key(in_string)
示例3: test_convert_base32_32_chars
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_32_chars(self):
"""Test Otp.convert_base32_secret_key().
Typical input string lengths are 16, 26, 32, and 64 significant
(ignoring padding) base32 characters. This tests a 32 character
base32 encoded secret
"""
cut = HOTP()
in_string = "nf2c a2lt ebqw y3ba mzxx k3df mqqh k4bo"
in_string = "".join(in_string.split()).upper()
expected_bytes = b"it is all fouled up."
actual_bytes = cut.convert_base32_secret_key(in_string)
self.assertEqual(expected_bytes, actual_bytes)
示例4: test_convert_base32_16_chars
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_16_chars(self):
"""Test Otp.convert_base32_secret_key().
Typical input string lengths are 16, 26, 32, and 64 significant
(ignoring padding) base32 characters. This tests a 16 character
base32 encoded secret.
"""
cut = HOTP()
in_string = "mfzw s5dv mf2g s33o"
in_string = "".join(in_string.split()).upper()
expected_bytes = b"asituation"
actual_bytes = cut.convert_base32_secret_key(in_string)
self.assertEqual(expected_bytes, actual_bytes)
示例5: test_convert_base32_64_chars
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_64_chars(self):
"""Test Otp.convert_base32_secret_key().
Typical input string lengths are 16, 26, 32, and 64 significant
(ignoring padding) base32 characters. This tests a 64 character
base32 encoded secret
"""
cut = HOTP()
in_string = "knux i5lb oruw 63ra nzxx e3lb nqwc a2lu e5zs" + \
" aylm nqqg m33v nrsw iidv oaqd ulji"
in_string = "".join(in_string.split()).upper()
expected_bytes = b"Situation normal, it\'s all fouled up :-("
actual_bytes = cut.convert_base32_secret_key(in_string)
self.assertEqual(expected_bytes, actual_bytes)
示例6: test_convert_base32_26_chars
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32_26_chars(self):
"""Test Otp.convert_base32_secret_key().
Typical input string lengths are 16, 26, 32, and 64 significant
(ignoring padding) base32 characters. This tests a 26 character
base32 encoded secret, which requires padding the base32 secret
before decoding
"""
cut = HOTP()
in_string = "onux i5lb oruw 63ra nzxx e3lb nq"
in_string = "".join(in_string.split()).upper()
expected_bytes = b"situation normal"
actual_bytes = cut.convert_base32_secret_key(in_string)
self.assertEqual(expected_bytes, actual_bytes)
示例7: test_convert_base32
# 需要导入模块: from authenticator import HOTP [as 别名]
# 或者: from authenticator.HOTP import convert_base32_secret_key [as 别名]
def test_convert_base32(self):
"""Test Otp.convert_base32_secret_key().
Check that expected byte strings are produced from base32 incoded
strings.
Uses test data and expected results from RFC4648, section10.
"""
cut = HOTP()
test_data = (
(b"", ""),
(b"f", "MY======"),
(b"fo", "MZXQ===="),
(b"foo", "MZXW6==="),
(b"foob", "MZXW6YQ="),
(b"fooba", "MZXW6YTB"),
(b"foobar", "MZXW6YTBOI======"))
for expected_bytes, in_string in test_data:
actual_bytes = cut.convert_base32_secret_key(in_string)
self.assertEqual(expected_bytes, actual_bytes)