當前位置: 首頁>>代碼示例>>Python>>正文


Python HOTP.counter_from_time方法代碼示例

本文整理匯總了Python中authenticator.HOTP.counter_from_time方法的典型用法代碼示例。如果您正苦於以下問題:Python HOTP.counter_from_time方法的具體用法?Python HOTP.counter_from_time怎麽用?Python HOTP.counter_from_time使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在authenticator.HOTP的用法示例。


在下文中一共展示了HOTP.counter_from_time方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_counter_from_time_period_wrong_type

# 需要導入模塊: from authenticator import HOTP [as 別名]
# 或者: from authenticator.HOTP import counter_from_time [as 別名]
    def test_counter_from_time_period_wrong_type(self):
        """Test Otp.counter_from_time().

        Check that providing a period that is not numeric or convertable
        to numeric raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
開發者ID:JeNeSuisPasDave,項目名稱:authenticator,代碼行數:12,代碼來源:test_hotp.py

示例2: test_counter_from_time_bad_period

# 需要導入模塊: from authenticator import HOTP [as 別名]
# 或者: from authenticator.HOTP import counter_from_time [as 別名]
    def test_counter_from_time_bad_period(self):
        """Test Otp.counter_from_time().

        Check that providing a bad period raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(ValueError):
            cut.counter_from_time(period="ABC")
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
開發者ID:JeNeSuisPasDave,項目名稱:authenticator,代碼行數:17,代碼來源:test_hotp.py

示例3: test_counter_from_time

# 需要導入模塊: from authenticator import HOTP [as 別名]
# 或者: from authenticator.HOTP import counter_from_time [as 別名]
    def test_counter_from_time(self):
        """Test Otp.counter_from_time().

        Check that the generated counter and remaining seconds make sense
        for the given period.

        """
        cut = HOTP()
        counter, remaining_seconds30 = cut.counter_from_time()
        counter30 = int.from_bytes(counter, byteorder='big', signed=False)
        counter, remaining_seconds60 = cut.counter_from_time(60)
        counter60 = int.from_bytes(counter, byteorder='big', signed=False)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(30, remaining_seconds30)
        self.assertLessEqual(0, remaining_seconds30)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(60, remaining_seconds60)
        self.assertLessEqual(0, remaining_seconds60)
        # Check that counter with period 60 is just about 1/2 of counter
        # with period 30
        #
        self.assertLessEqual(counter60 * 2, counter30)
        self.assertGreater(counter60 * 2 + 2, counter30)
開發者ID:JeNeSuisPasDave,項目名稱:authenticator,代碼行數:25,代碼來源:test_hotp.py


注:本文中的authenticator.HOTP.counter_from_time方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。