Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/exceptions.py: 86%

37 statements  

« prev     ^ index     » next       coverage.py v7.0.1, created at 2022-12-25 06:11 +0000

1# This file is dual licensed under the terms of the Apache License, Version 

2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 

3# for complete details. 

4 

5 

6import typing 

7 

8from cryptography import utils 

9 

10if typing.TYPE_CHECKING: 

11 from cryptography.hazmat.bindings.openssl.binding import ( 

12 _OpenSSLErrorWithText, 

13 ) 

14 

15 

16class _Reasons(utils.Enum): 

17 BACKEND_MISSING_INTERFACE = 0 

18 UNSUPPORTED_HASH = 1 

19 UNSUPPORTED_CIPHER = 2 

20 UNSUPPORTED_PADDING = 3 

21 UNSUPPORTED_MGF = 4 

22 UNSUPPORTED_PUBLIC_KEY_ALGORITHM = 5 

23 UNSUPPORTED_ELLIPTIC_CURVE = 6 

24 UNSUPPORTED_SERIALIZATION = 7 

25 UNSUPPORTED_X509 = 8 

26 UNSUPPORTED_EXCHANGE_ALGORITHM = 9 

27 UNSUPPORTED_DIFFIE_HELLMAN = 10 

28 UNSUPPORTED_MAC = 11 

29 

30 

31class UnsupportedAlgorithm(Exception): 

32 def __init__( 

33 self, message: str, reason: typing.Optional[_Reasons] = None 

34 ) -> None: 

35 super(UnsupportedAlgorithm, self).__init__(message) 

36 self._reason = reason 

37 

38 

39class AlreadyFinalized(Exception): 

40 pass 

41 

42 

43class AlreadyUpdated(Exception): 

44 pass 

45 

46 

47class NotYetFinalized(Exception): 

48 pass 

49 

50 

51class InvalidTag(Exception): 

52 pass 

53 

54 

55class InvalidSignature(Exception): 

56 pass 

57 

58 

59class InternalError(Exception): 

60 def __init__( 

61 self, msg: str, err_code: typing.List["_OpenSSLErrorWithText"] 

62 ) -> None: 

63 super(InternalError, self).__init__(msg) 

64 self.err_code = err_code 

65 

66 

67class InvalidKey(Exception): 

68 pass