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)
21     { super("Out of bounds: " ~ err); }
22 }
23 
24 /**
25 * InvalidArgument Exception
26 */
27 class InvalidArgument : Exception
28 {
29     @safe pure nothrow this(in string err)
30     { super("Invalid argument: " ~ err); }
31 }
32 
33 /**
34 * InvalidState Exception
35 */
36 class InvalidState : Exception
37 {
38     @safe pure nothrow this(in string err)
39     { super(err); }
40 }
41 
42 /**
43 * Logic_Error Exception
44 */
45 final class LogicError : Exception
46 {
47     @safe pure nothrow this(in string err)
48     { super(err); }
49 }
50 
51 /**
52 * LookupError Exception
53 */
54 class LookupError : Exception
55 {
56     @safe pure nothrow this(in string err)
57     { super(err); }
58 }
59 
60 /**
61 * InternalError Exception
62 */
63 class InternalError : Exception
64 {
65     @safe pure nothrow this(in string err) 
66     { super("Internal error: " ~ err); }
67 }
68 
69 /**
70 * InvalidKeyLength Exception
71 */
72 final class InvalidKeyLength : InvalidArgument
73 {
74     @safe pure nothrow this(in string name, size_t length) {
75         super(name ~ " cannot accept a key of length " ~
76               to!string(length));
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) {
86         super("IV length " ~ to!string(bad_len) ~ " is invalid for " ~ mode);
87     }
88 }
89 
90 /**
91 * PRNGUnseeded Exception
92 */
93 final class PRNGUnseeded : InvalidState
94 {
95     @safe pure nothrow this(in string algo) {
96         super("PRNG not seeded: " ~ algo);
97     }
98 }
99 
100 /**
101 * PolicyViolation Exception
102 */
103 final class PolicyViolation : InvalidState
104 {
105     @safe pure nothrow this(in string err) {
106         super("TLSPolicy violation: " ~ err);
107     }
108 }
109 
110 /**
111 * AlgorithmNotFound Exception
112 */
113 final class AlgorithmNotFound : LookupError
114 {
115     @safe pure nothrow this(in string name) {
116         super("Could not find any algorithm named \"" ~ name ~ "\"");
117     }
118 }
119 
120 /**
121 * InvalidAlgorithmName Exception
122 */
123 final class InvalidAlgorithmName : InvalidArgument
124 {
125     @safe pure nothrow this(in string name) {
126         super("Invalid algorithm name: " ~ name);
127     }
128 }
129 
130 /**
131 * EncodingError Exception
132 */
133 final class EncodingError : InvalidArgument
134 {
135     @safe pure nothrow this(in string name) {
136         super("Encoding error: " ~ name);
137     }
138 }
139 
140 /**
141 * DecodingError Exception
142 */
143 class DecodingError : InvalidArgument
144 {
145     @safe pure nothrow this(in string name) 
146     {
147         super("Decoding error: " ~ name);
148     }
149 }
150 
151 /**
152 * IntegrityFailure Exception
153 */
154 final class IntegrityFailure : Exception
155 {
156     @safe pure nothrow this(in string msg) {
157         super("Integrity failure: " ~ msg);
158     }
159 }
160 
161 /**
162 * InvalidOID Exception
163 */
164 final class InvalidOID : DecodingError
165 {
166     @safe pure nothrow this(in string oid) {
167         super("Invalid ASN.1 OID: " ~ oid);
168     }
169 }
170 
171 /**
172 * StreamIOError Exception
173 */
174 final class StreamIOError : Exception
175 {
176     @safe pure nothrow this(in string err) {
177         super("I/O error: " ~ err);
178     }
179 }
180 
181 /**
182 * Self Test Failure Exception
183 */
184 final class SelfTestFailure : InternalError
185 {
186     @safe pure nothrow this(in string err) {
187         super("Self test failed: " ~ err);
188     }
189 }
190 
191 /**
192 * Memory Allocation Exception
193 */
194 final class MemoryExhaustion : Exception
195 {
196     @safe pure nothrow this(in string err) {
197         super("Memory Exhaustion: " ~ err);
198     }
199 
200     string what() const nothrow pure
201     { return "Ran out of memory, allocation failed"; }
202 }