1 /**
2 * Exceptions
3 * 
4 * Copyright:
5 * (C) 1999-2009 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 module botan.utils.exceptn;
12 
13 import botan.utils.types;
14 import botan.utils.parsing;
15 import std.exception;
16 import std.conv : to;
17 @safe pure nothrow :
18 class RangeError : Exception
19 {
20 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__)
21 	{ super("Out of bounds: " ~ err, next, file, line); }
22 }
23 
24 /**
25 * InvalidArgument Exception
26 */
27 class InvalidArgument : Exception
28 {
29 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__)
30 	{ super("Invalid argument: " ~ err, next, file, line); }
31 }
32 
33 /**
34 * InvalidState Exception
35 */
36 class InvalidState : Exception
37 {
38 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__)
39 	{ super(err, next, file, line); }
40 }
41 
42 /**
43 * Logic_Error Exception
44 */
45 final class LogicError : Exception
46 {
47 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__)
48 	{ super(err, next, file, line); }
49 }
50 
51 /**
52 * LookupError Exception
53 */
54 class LookupError : Exception
55 {
56 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__)
57 	{ super(err, next, file, line); }
58 }
59 
60 /**
61 * InternalError Exception
62 */
63 class InternalError : Exception
64 {
65 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__) 
66 	{ super("Internal error: " ~ err, next, file, line); }
67 }
68 
69 /**
70 * InvalidKeyLength Exception
71 */
72 final class InvalidKeyLength : InvalidArgument
73 {
74 	@safe pure nothrow this(in string name, size_t length, Throwable next = null, string file = __FILE__, int line = __LINE__) {
75         super(name ~ " cannot accept a key of length " ~
76 			to!string(length), next, file, line);
77     }
78 }
79 
80 /**
81 * InvalidIVLength Exception
82 */
83 final class InvalidIVLength : InvalidArgument
84 {
85 	@safe pure nothrow this(in string mode, size_t bad_len, Throwable next = null, string file = __FILE__, int line = __LINE__) {
86 		super("IV length " ~ to!string(bad_len) ~ " is invalid for " ~ mode, next, file, line);
87     }
88 }
89 
90 /**
91 * PRNGUnseeded Exception
92 */
93 final class PRNGUnseeded : InvalidState
94 {
95 	@safe pure nothrow this(in string algo, Throwable next = null, string file = __FILE__, int line = __LINE__) {
96 		super("PRNG not seeded: " ~ algo, next, file, line);
97     }
98 }
99 
100 /**
101 * PolicyViolation Exception
102 */
103 final class PolicyViolation : InvalidState
104 {
105 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__) {
106 		super("TLSPolicy violation: " ~ err, next, file, line);
107     }
108 }
109 
110 /**
111 * AlgorithmNotFound Exception
112 */
113 final class AlgorithmNotFound : LookupError
114 {
115 	@safe pure nothrow this(in string name, Throwable next = null, string file = __FILE__, int line = __LINE__) {
116 		super("Could not find any algorithm named \"" ~ name ~ "\"", next, file, line);
117     }
118 }
119 
120 /**
121 * InvalidAlgorithmName Exception
122 */
123 final class InvalidAlgorithmName : InvalidArgument
124 {
125 	@safe pure nothrow this(in string name, Throwable next = null, string file = __FILE__, int line = __LINE__) {
126 		super("Invalid algorithm name: " ~ name, next, file, line);
127     }
128 }
129 
130 /**
131 * EncodingError Exception
132 */
133 final class EncodingError : InvalidArgument
134 {
135 	@safe pure nothrow this(in string name, Throwable next = null, string file = __FILE__, int line = __LINE__) {
136 		super("Encoding error: " ~ name, next, file, line);
137     }
138 }
139 
140 /**
141 * DecodingError Exception
142 */
143 class DecodingError : InvalidArgument
144 {
145 	@safe pure nothrow this(in string name, Throwable next = null, string file = __FILE__, int line = __LINE__) 
146     {
147 		super("Decoding error: " ~ name, next, file, line);
148     }
149 }
150 
151 /**
152 * IntegrityFailure Exception
153 */
154 final class IntegrityFailure : Exception
155 {
156 	@safe pure nothrow this(in string msg, Throwable next = null, string file = __FILE__, int line = __LINE__) {
157 		super("Integrity failure: " ~ msg, next, file, line);
158     }
159 }
160 
161 /**
162 * InvalidOID Exception
163 */
164 final class InvalidOID : DecodingError
165 {
166 	@safe pure nothrow this(in string oid, Throwable next = null, string file = __FILE__, int line = __LINE__) {
167 		super("Invalid ASN.1 OID: " ~ oid, next, file, line);
168     }
169 }
170 
171 /**
172 * StreamIOError Exception
173 */
174 final class StreamIOError : Exception
175 {
176 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__) {
177 		super("I/O error: " ~ err, next, file, line);
178     }
179 }
180 
181 /**
182 * Self Test Failure Exception
183 */
184 final class SelfTestFailure : InternalError
185 {
186 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__) {
187 		super("Self test failed: " ~ err, next, file, line);
188     }
189 }
190 
191 /**
192 * Memory Allocation Exception
193 */
194 final class MemoryExhaustion : Exception
195 {
196 	@safe pure nothrow this(in string err, Throwable next = null, string file = __FILE__, int line = __LINE__) {
197 		super("Memory Exhaustion: " ~ err, next, file, line);
198     }
199 
200     string what() const nothrow pure
201     { return "Ran out of memory, allocation failed"; }
202 }