1 module itsdangerous.exc;
2 
3 import std.datetime.date;
4 
5 class BadData : Exception {
6     this(string msg, string file = __FILE__, size_t line = __LINE__) {
7         super(msg, file, line);
8     }
9 }
10 
11 class BadSignature : BadData {
12     /+ Raised if a signature does not match. +/
13     string payload;
14     string header;
15     
16     this(string msg, string file = __FILE__, size_t line = __LINE__, string payload = null) {
17         super(msg, file, line);
18         /+
19         #: The payload that failed the signature test. In some
20         #: situations you might still want to inspect this, even if
21         #: you know it was tampered with.
22         +/
23         this.payload = payload;
24     }
25 }
26 
27 class BadTimeSignature : BadSignature {
28     /+
29     Raised if a time-based signature is invalid. This is a subclass
30     of :class:`BadSignature`.
31     +/
32     string dateSignedStr;
33     this(string msg, string file = __FILE__, size_t line = __LINE__,
34         string payload = null, string dateSignedStr = null) {
35         super(msg, file, line, payload);
36         /+
37         #: If the signature expired this exposes the date of when the
38         #: signature was created. This can be helpful in order to
39         #: tell the user how long a link has been gone stale.
40         #:
41         +/
42         this.dateSignedStr = dateSignedStr;
43     }
44 }
45 
46 class SignatureExpired : BadTimeSignature {
47     /+Raised if a signature timestamp is older than ``max_age``. This
48     is a subclass of :exc:`BadTimeSignature`.
49     +/
50     this(string msg, string file = __FILE__, size_t line = __LINE__,
51         string payload = null, string dateSignedStr = null) {
52         super(msg, file, line, payload, dateSignedStr);
53     }
54 }
55 
56 class BadHeader : BadSignature {
57     /+Raised if a signed header is invalid in some form. This only
58     happens for serializers that have a header that goes with the
59     signature.
60     +/
61     string originalError;
62     this(string msg, string file = __FILE__, size_t line = __LINE__,
63         string payload = null, string header=null, string originalError = null ){
64         super(msg, file, line, payload);
65         /+
66         #: If the header is actually available but just malformed it
67         #: might be stored here.
68         self.header = header
69 
70         #: If available, the error that indicates why the payload was
71         #: not valid. This might be ``None``.
72         +/
73         this.originalError = originalError;
74     }
75 }
76 
77 class BadPayload : BadData {
78     /+Raised if a payload is invalid. This could happen if the payload
79     is loaded despite an invalid signature, or if there is a mismatch
80     between the serializer and deserializer. The original exception
81     that occurred during loading is stored on as :attr:`original_error`.
82     +/
83     string originalError;
84     this(string msg, string file = __FILE__, size_t line = __LINE__, string originalError = null){
85         super(msg);
86         /+
87         #: If available, the error that indicates why the payload was
88         #: not valid. This might be ``None``.
89         self.original_error = original_error
90         +/
91         this.originalError = originalError;
92     }
93 }