diff options
Diffstat (limited to 'otp2289')
| -rw-r--r-- | otp2289/__main__.py | 12 | ||||
| -rw-r--r-- | otp2289/generator.py | 18 | ||||
| -rw-r--r-- | otp2289/server.py | 27 |
3 files changed, 27 insertions, 30 deletions
diff --git a/otp2289/__main__.py b/otp2289/__main__.py index 2962d29..7c71040 100644 --- a/otp2289/__main__.py +++ b/otp2289/__main__.py | |||
| @@ -55,9 +55,9 @@ def generate_otp_response(args): | |||
| 55 | :param args: The arguments assigned from argparse | 55 | :param args: The arguments assigned from argparse |
| 56 | :type args: argparse.Namespace | 56 | :type args: argparse.Namespace |
| 57 | 57 | ||
| 58 | :raises OTPChallengeException: In case of invalid challenge | 58 | :raises otp2289.OTPChallengeException: If the challenge is invalid |
| 59 | 59 | ||
| 60 | :raises OTPGeneratorException: In case of wrong generator parameters | 60 | :raises otp2289.OTPGeneratorException: If generator parameters are wrong |
| 61 | 61 | ||
| 62 | :return: The response string | 62 | :return: The response string |
| 63 | :rtype: str | 63 | :rtype: str |
| @@ -89,9 +89,9 @@ def generate_otp_range(args): | |||
| 89 | :param args: The arguments assigned from argparse | 89 | :param args: The arguments assigned from argparse |
| 90 | :type args: argparse.Namespace | 90 | :type args: argparse.Namespace |
| 91 | 91 | ||
| 92 | :raises OTPChallengeException: In case of invalid challenge | 92 | :raises otp2289.OTPChallengeException: If the challenge is invalid |
| 93 | 93 | ||
| 94 | :raises OTPGeneratorException: In case of wrong generator parameters | 94 | :raises otp2289.OTPGeneratorException: If generator parameters are wrong |
| 95 | 95 | ||
| 96 | :return: The responses string | 96 | :return: The responses string |
| 97 | :rtype: str | 97 | :rtype: str |
| @@ -137,9 +137,9 @@ def initiate_new_sequence(args): | |||
| 137 | :param args: The arguments assigned from argparse | 137 | :param args: The arguments assigned from argparse |
| 138 | :type args: argparse.Namespace | 138 | :type args: argparse.Namespace |
| 139 | 139 | ||
| 140 | :raises OTPChallengeException: In case of invalid challenge | 140 | :raises otp2289.OTPChallengeException: If the challenge is invalid |
| 141 | 141 | ||
| 142 | :raises OTPGeneratorException: In case of wrong generator parameters | 142 | :raises otp2289.OTPGeneratorException: If generator parameters are wrong |
| 143 | 143 | ||
| 144 | :return: The response string | 144 | :return: The response string |
| 145 | :rtype: str | 145 | :rtype: str |
diff --git a/otp2289/generator.py b/otp2289/generator.py index ac3bb3c..4623dc0 100644 --- a/otp2289/generator.py +++ b/otp2289/generator.py | |||
| @@ -310,7 +310,6 @@ class OTPGenerator: | |||
| 310 | """ | 310 | """ |
| 311 | Constructs an OTPGenerator object with a given password and seed. | 311 | Constructs an OTPGenerator object with a given password and seed. |
| 312 | 312 | ||
| 313 | Keyword Arguments: | ||
| 314 | :param password: The password string | 313 | :param password: The password string |
| 315 | :type password: bytes | 314 | :type password: bytes |
| 316 | 315 | ||
| @@ -320,7 +319,7 @@ class OTPGenerator: | |||
| 320 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 | 319 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 |
| 321 | :type hash_algo: int or str | 320 | :type hash_algo: int or str |
| 322 | 321 | ||
| 323 | :raises OTPGeneratorException: In case the input does not validate | 322 | :raises otp2289.OTPGeneratorException: If the input does not validate |
| 324 | """ | 323 | """ |
| 325 | # enforce the rfc2289 constraints | 324 | # enforce the rfc2289 constraints |
| 326 | self._seed = seed | 325 | self._seed = seed |
| @@ -389,7 +388,7 @@ class OTPGenerator: | |||
| 389 | :param challenge: The challenge string described in RFC-2289 | 388 | :param challenge: The challenge string described in RFC-2289 |
| 390 | :type challenge: str | 389 | :type challenge: str |
| 391 | 390 | ||
| 392 | :raises OTPChallengeException: When the challenge string is invalid | 391 | :raises otp2289.OTPChallengeException: If the challenge is invalid |
| 393 | 392 | ||
| 394 | :return: (seed, hash_algo, step) tuple. | 393 | :return: (seed, hash_algo, step) tuple. |
| 395 | :rtype: tuple | 394 | :rtype: tuple |
| @@ -485,7 +484,7 @@ class OTPGenerator: | |||
| 485 | :param tokens_str: String representing 6 words tokens | 484 | :param tokens_str: String representing 6 words tokens |
| 486 | :type tokens_str: str | 485 | :type tokens_str: str |
| 487 | 486 | ||
| 488 | :raises OTPGeneratorException: When the tokens_str is invalid | 487 | :raises otp2289.OTPGeneratorException: When the tokens_str is invalid |
| 489 | 488 | ||
| 490 | :return: 6 words tokens | 489 | :return: 6 words tokens |
| 491 | :rtype: bytes | 490 | :rtype: bytes |
| @@ -529,7 +528,7 @@ class OTPGenerator: | |||
| 529 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 | 528 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 |
| 530 | :type hash_algo: int or str | 529 | :type hash_algo: int or str |
| 531 | 530 | ||
| 532 | :raises OTPGeneratorException: In case hash_algo does not validate | 531 | :raises otp2289.OTPGeneratorException: If hash_algo does not validate |
| 533 | 532 | ||
| 534 | :return: The validated hash_algo in str-form | 533 | :return: The validated hash_algo in str-form |
| 535 | :rtype: str | 534 | :rtype: str |
| @@ -556,7 +555,7 @@ class OTPGenerator: | |||
| 556 | :param seed: The seed received from the challenge, defaults to '' | 555 | :param seed: The seed received from the challenge, defaults to '' |
| 557 | :type seed: str | 556 | :type seed: str |
| 558 | 557 | ||
| 559 | :raises OTPGeneratorException: In case seed does not validate | 558 | :raises otp2289.OTPGeneratorException: If seed does not validate |
| 560 | 559 | ||
| 561 | :return: The validated (and very same) seed | 560 | :return: The validated (and very same) seed |
| 562 | :rtype: str | 561 | :rtype: str |
| @@ -580,7 +579,7 @@ class OTPGenerator: | |||
| 580 | :param seed: The step received from the challenge | 579 | :param seed: The step received from the challenge |
| 581 | :type seed: int | 580 | :type seed: int |
| 582 | 581 | ||
| 583 | :raises OTPGeneratorException: In case step does not validate | 582 | :raises otp2289.OTPGeneratorException: If step does not validate |
| 584 | 583 | ||
| 585 | :return: The validated (and very same) step | 584 | :return: The validated (and very same) step |
| 586 | :rtype: int | 585 | :rtype: int |
| @@ -595,7 +594,6 @@ class OTPGenerator: | |||
| 595 | """ | 594 | """ |
| 596 | Generates the OTP hexdigest for the given step. | 595 | Generates the OTP hexdigest for the given step. |
| 597 | 596 | ||
| 598 | Keyword Arguments: | ||
| 599 | :param step: The step to generate OTP for | 597 | :param step: The step to generate OTP for |
| 600 | :type step: int | 598 | :type step: int |
| 601 | 599 | ||
| @@ -614,7 +612,6 @@ class OTPGenerator: | |||
| 614 | extract these parameters. The syntax of the challenge is: | 612 | extract these parameters. The syntax of the challenge is: |
| 615 | otp-<algorithm identifier> <sequence integer> <seed> | 613 | otp-<algorithm identifier> <sequence integer> <seed> |
| 616 | 614 | ||
| 617 | Keyword Arguments: | ||
| 618 | :param challenge: The challenge string | 615 | :param challenge: The challenge string |
| 619 | :type challenge: str | 616 | :type challenge: str |
| 620 | 617 | ||
| @@ -630,7 +627,6 @@ class OTPGenerator: | |||
| 630 | """ | 627 | """ |
| 631 | Generates the OTP six words token for the given step. | 628 | Generates the OTP six words token for the given step. |
| 632 | 629 | ||
| 633 | Keyword Arguments: | ||
| 634 | :param step: The step to generate OTP for | 630 | :param step: The step to generate OTP for |
| 635 | :type step: int | 631 | :type step: int |
| 636 | 632 | ||
| @@ -649,7 +645,6 @@ class OTPGenerator: | |||
| 649 | extract these parameters. The syntax of the challenge is: | 645 | extract these parameters. The syntax of the challenge is: |
| 650 | otp-<algorithm identifier> <sequence integer> <seed> | 646 | otp-<algorithm identifier> <sequence integer> <seed> |
| 651 | 647 | ||
| 652 | Keyword Arguments: | ||
| 653 | :param challenge: The challenge string | 648 | :param challenge: The challenge string |
| 654 | :type challenge: str | 649 | :type challenge: str |
| 655 | 650 | ||
| @@ -709,7 +704,6 @@ class OTPGenerator: | |||
| 709 | """ | 704 | """ |
| 710 | Generates the OTP bytes for the given step. | 705 | Generates the OTP bytes for the given step. |
| 711 | 706 | ||
| 712 | Keyword Arguments: | ||
| 713 | :param step: The step to generate OTP for | 707 | :param step: The step to generate OTP for |
| 714 | :type step: int | 708 | :type step: int |
| 715 | 709 | ||
diff --git a/otp2289/server.py b/otp2289/server.py index fca3f06..119fbff 100644 --- a/otp2289/server.py +++ b/otp2289/server.py | |||
| @@ -71,7 +71,7 @@ class OTPState: | |||
| 71 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 | 71 | :param hash_algo: The hash algo, defaults to OTP_ALGO_MD5 |
| 72 | :type hash_algo: int or str | 72 | :type hash_algo: int or str |
| 73 | 73 | ||
| 74 | :raises OTPStateException: In case the input does not validate | 74 | :raises otp2289.OTPStateException: If the input does not validate |
| 75 | """ | 75 | """ |
| 76 | # enforce the rfc2289 constraints | 76 | # enforce the rfc2289 constraints |
| 77 | try: | 77 | try: |
| @@ -126,7 +126,7 @@ class OTPState: | |||
| 126 | :type dict_obj: dict | 126 | :type dict_obj: dict |
| 127 | 127 | ||
| 128 | :return: A new OTPState object | 128 | :return: A new OTPState object |
| 129 | :rtype: OTPStore | 129 | :rtype: otp2289.OTPStore |
| 130 | """ | 130 | """ |
| 131 | return cls(**dict_obj) | 131 | return cls(**dict_obj) |
| 132 | 132 | ||
| @@ -144,8 +144,9 @@ class OTPState: | |||
| 144 | :param response: The response to this state (its challenge) | 144 | :param response: The response to this state (its challenge) |
| 145 | :type response: str | 145 | :type response: str |
| 146 | 146 | ||
| 147 | :raises OTPInvalidResponse: If the response is corrupt / illegal, | 147 | :raises otp2289.OTPInvalidResponse: If the response is corrupt/illegal, |
| 148 | but not if it simply does not validate | 148 | but not if it simply does not |
| 149 | validate | ||
| 149 | 150 | ||
| 150 | :return: The bytes representation of response (if any) | 151 | :return: The bytes representation of response (if any) |
| 151 | :rtype: bytes | 152 | :rtype: bytes |
| @@ -168,7 +169,7 @@ class OTPState: | |||
| 168 | :param ot_hex: The one-time hex to validate | 169 | :param ot_hex: The one-time hex to validate |
| 169 | :type ot_hex: str | 170 | :type ot_hex: str |
| 170 | 171 | ||
| 171 | :raises OTPStateException: In case hex does not validate | 172 | :raises otp2289.OTPStateException: If hex does not validate |
| 172 | 173 | ||
| 173 | :return: The validated hex (without leading 0x) converted to bytes | 174 | :return: The validated hex (without leading 0x) converted to bytes |
| 174 | :rtype: bytes | 175 | :rtype: bytes |
| @@ -194,7 +195,7 @@ class OTPState: | |||
| 194 | where step -= 1 and ot_hex = self._new_digest_hex | 195 | where step -= 1 and ot_hex = self._new_digest_hex |
| 195 | 196 | ||
| 196 | :return: The next OTPState if validated, None otherwise | 197 | :return: The next OTPState if validated, None otherwise |
| 197 | :rtype: OTPState or None | 198 | :rtype: otp2289.OTPState or None |
| 198 | """ | 199 | """ |
| 199 | if self._new_digest_hex is None: | 200 | if self._new_digest_hex is None: |
| 200 | return None | 201 | return None |
| @@ -213,7 +214,8 @@ class OTPState: | |||
| 213 | :param store_valid_response: Should a valid response be stored | 214 | :param store_valid_response: Should a valid response be stored |
| 214 | :type store_valid_response: bool | 215 | :type store_valid_response: bool |
| 215 | 216 | ||
| 216 | :raises OTPInvalidResponse: If the response does not match this state | 217 | :raises otp2289.OTPInvalidResponse: If the response does not match |
| 218 | this state | ||
| 217 | 219 | ||
| 218 | :return: Returns True if response validates, False otherwise | 220 | :return: Returns True if response validates, False otherwise |
| 219 | :rtype: bool | 221 | :rtype: bool |
| @@ -328,9 +330,9 @@ class OTPStore: | |||
| 328 | :type key: str | 330 | :type key: str |
| 329 | 331 | ||
| 330 | :param state: The OTPState object | 332 | :param state: The OTPState object |
| 331 | :type state: OTPState | 333 | :type state: otp2289.OTPState |
| 332 | 334 | ||
| 333 | :raises OTPStoreException: On failure | 335 | :raises otp2289.OTPStoreException: On failure |
| 334 | """ | 336 | """ |
| 335 | if not isinstance(key, str): | 337 | if not isinstance(key, str): |
| 336 | raise OTPStoreException('key must be a str') | 338 | raise OTPStoreException('key must be a str') |
| @@ -356,10 +358,10 @@ class OTPStore: | |||
| 356 | 358 | ||
| 357 | :raises KeyError: If key does not exist | 359 | :raises KeyError: If key does not exist |
| 358 | 360 | ||
| 359 | :raises OTPStoreException: On failure | 361 | :raises otp2289.OTPStoreException: On failure |
| 360 | 362 | ||
| 361 | :return: The state corresponding to the key | 363 | :return: The state corresponding to the key |
| 362 | :rtype: OTPState | 364 | :rtype: otp2289.OTPState |
| 363 | """ | 365 | """ |
| 364 | if not isinstance(key, str): | 366 | if not isinstance(key, str): |
| 365 | raise OTPStoreException('key must be a str') | 367 | raise OTPStoreException('key must be a str') |
| @@ -387,7 +389,8 @@ class OTPStore: | |||
| 387 | 389 | ||
| 388 | :raises KeyError: If the key is not present | 390 | :raises KeyError: If the key is not present |
| 389 | 391 | ||
| 390 | :raises OTPInvalidResponse: If the response does not match this state | 392 | :raises otp2289.OTPInvalidResponse: If the response does not match |
| 393 | this state | ||
| 391 | 394 | ||
| 392 | :return: Returns True if response validates, False otherwise | 395 | :return: Returns True if response validates, False otherwise |
| 393 | :rtype: bool | 396 | :rtype: bool |
