File: exceptions.py

package info (click to toggle)
python-securesystemslib 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,316 kB
  • sloc: python: 5,319; sh: 38; makefile: 5
file content (61 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
<Program Name>
  exceptions.py

<Author>
  Santiago Torres-Arias <santiago@nyu.edu>
  Lukas Puehringer <lukas.puehringer@nyu.edu>

<Started>
  Dec 8, 2017

<Copyright>
  See LICENSE for licensing information.

<Purpose>
  Define Exceptions used in the gpg package. Following the practice from
  securesystemslib the names chosen for exception classes should end in
  'Error' (except where there is a good reason not to).

"""

import datetime


class PacketParsingError(Exception):
    pass


class KeyNotFoundError(Exception):
    pass


class PacketVersionNotSupportedError(Exception):
    pass


class SignatureAlgorithmNotSupportedError(Exception):
    pass


class KeyExpirationError(Exception):
    def __init__(self, key):
        super().__init__()
        self.key = key

    def __str__(self):
        creation_time = datetime.datetime.utcfromtimestamp(self.key["creation_time"])
        expiration_time = datetime.datetime.utcfromtimestamp(
            self.key["creation_time"] + self.key["validity_period"]
        )
        validity_period = expiration_time - creation_time

        return (
            "GPG key '{}' created on '{:%Y-%m-%d %H:%M} UTC' with validity "
            "period '{}' expired on '{:%Y-%m-%d %H:%M} UTC'.".format(
                self.key["keyid"],
                creation_time,
                validity_period,
                expiration_time,
            )
        )