Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/Crypto/__init__.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1from __future__ import annotations 

2 

3from typing import Union 

4 

5__all__ = [ 

6 "Cipher", 

7 "Hash", 

8 "Protocol", 

9 "PublicKey", 

10 "Util", 

11 "Signature", 

12 "IO", 

13 "Math", 

14 "PassphraseRequiredError", 

15 "IncorrectPassphraseError", 

16 "MessageTooLongError", 

17 "KdfLimitError", 

18 "KdfIterationLimitError", 

19 "KdfMemoryLimitError", 

20] 

21 

22version_info: tuple[int, int, Union[int, str]] = (4, 0, "1") 

23 

24__version__: str = ".".join([str(x) for x in version_info]) 

25 

26 

27class PassphraseRequiredError(ValueError): 

28 """The data (for instance, a private key) is encrypted, 

29 but no passphrase was provided. 

30 

31 This is a subclass of ``ValueError``. 

32 """ 

33 

34 

35class IncorrectPassphraseError(ValueError): 

36 """The encrypted data (for instance, a private key) could not be 

37 decrypted with the passphrase. 

38 

39 Most likely, the passphrase is wrong; but the encrypted data might also 

40 be corrupted (the two cases cannot be told apart). 

41 

42 This is a subclass of ``ValueError``. 

43 """ 

44 

45 

46class MessageTooLongError(ValueError, OverflowError): 

47 """The data is longer than a cipher can process with the same key 

48 and nonce (for instance, the key stream would repeat). 

49 

50 This is a subclass of both ``ValueError`` and ``OverflowError``. 

51 """ 

52 

53 

54class KdfLimitError(ValueError): 

55 """Deriving a key from a password or a passphrase would take more time 

56 or memory than allowed, as set to protect against malicious data 

57 (for instance, an encrypted private key or a password hash that 

58 states an extremely high cost). 

59 

60 This is a subclass of ``ValueError``. 

61 """ 

62 

63 

64class KdfIterationLimitError(KdfLimitError): 

65 """The cost of the key derivation (the iteration count of PBKDF2, 

66 the cost of scrypt, or the rounds of bcrypt) is above the limit 

67 (for instance, the one set with ``max_iteration_count``). 

68 """ 

69 

70 

71class KdfMemoryLimitError(KdfLimitError): 

72 """The key derivation needs more memory than the limit 

73 (for instance, the one set with ``max_memory``). 

74 """ 

75 

76 

77_PASSPHRASE_REQUIRED = "The private key is encrypted: a passphrase is required" 

78_INCORRECT_PASSPHRASE = "Incorrect passphrase (or the encrypted private key is corrupted)"