Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/securesystemslib/_gpg/exceptions.py: 68%

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

19 statements  

1""" 

2<Program Name> 

3 exceptions.py 

4 

5<Author> 

6 Santiago Torres-Arias <santiago@nyu.edu> 

7 Lukas Puehringer <lukas.puehringer@nyu.edu> 

8 

9<Started> 

10 Dec 8, 2017 

11 

12<Copyright> 

13 See LICENSE for licensing information. 

14 

15<Purpose> 

16 Define Exceptions used in the gpg package. Following the practice from 

17 securesystemslib the names chosen for exception classes should end in 

18 'Error' (except where there is a good reason not to). 

19 

20""" 

21 

22import datetime 

23 

24 

25class PacketParsingError(Exception): 

26 pass 

27 

28 

29class KeyNotFoundError(Exception): 

30 pass 

31 

32 

33class PacketVersionNotSupportedError(Exception): 

34 pass 

35 

36 

37class SignatureAlgorithmNotSupportedError(Exception): 

38 pass 

39 

40 

41class KeyExpirationError(Exception): 

42 def __init__(self, key): 

43 super().__init__() 

44 self.key = key 

45 

46 def __str__(self): 

47 creation_time = datetime.datetime.utcfromtimestamp(self.key["creation_time"]) 

48 expiration_time = datetime.datetime.utcfromtimestamp( 

49 self.key["creation_time"] + self.key["validity_period"] 

50 ) 

51 validity_period = expiration_time - creation_time 

52 

53 return ( 

54 "GPG key '{}' created on '{:%Y-%m-%d %H:%M} UTC' with validity " 

55 "period '{}' expired on '{:%Y-%m-%d %H:%M} UTC'.".format( 

56 self.key["keyid"], 

57 creation_time, 

58 validity_period, 

59 expiration_time, 

60 ) 

61 )