/src/p11-kit/p11-kit/messages.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2011 Collabora Ltd. |
3 | | * |
4 | | * Redistribution and use in source and binary forms, with or without |
5 | | * modification, are permitted provided that the following conditions |
6 | | * are met: |
7 | | * |
8 | | * * Redistributions of source code must retain the above |
9 | | * copyright notice, this list of conditions and the |
10 | | * following disclaimer. |
11 | | * * Redistributions in binary form must reproduce the |
12 | | * above copyright notice, this list of conditions and |
13 | | * the following disclaimer in the documentation and/or |
14 | | * other materials provided with the distribution. |
15 | | * * The names of contributors to this software may not be |
16 | | * used to endorse or promote products derived from this |
17 | | * software without specific prior written permission. |
18 | | * |
19 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
22 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
23 | | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
24 | | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
25 | | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
26 | | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
27 | | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
28 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
29 | | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
30 | | * DAMAGE. |
31 | | * |
32 | | * Author: Stef Walter <stefw@collabora.co.uk> |
33 | | */ |
34 | | |
35 | | #include "config.h" |
36 | | |
37 | | #include "pkcs11.h" |
38 | | #include "p11-kit.h" |
39 | | |
40 | | /** |
41 | | * SECTION:p11-kit-util |
42 | | * @title: Utilities |
43 | | * @short_description: PKCS\#11 utilities |
44 | | * |
45 | | * Utility functions for working with PKCS\#11. |
46 | | */ |
47 | | |
48 | | #ifdef ENABLE_NLS |
49 | | #include <libintl.h> |
50 | 0 | #define _(x) dgettext(PACKAGE_NAME, x) |
51 | | #else |
52 | | #define _(x) (x) |
53 | | #endif |
54 | | |
55 | | /** |
56 | | * p11_kit_strerror: |
57 | | * @rv: The code to get a message for. |
58 | | * |
59 | | * Get a message for a PKCS\#11 return value or error code. Do not |
60 | | * pass CKR_OK or other such non errors to this function. |
61 | | * |
62 | | * Returns: The user readable and localized message. |
63 | | **/ |
64 | | const char* |
65 | | p11_kit_strerror (CK_RV rv) |
66 | 0 | { |
67 | 0 | switch (rv) { |
68 | | |
69 | | /* These are not really errors, or not current */ |
70 | 0 | case CKR_OK: |
71 | 0 | case CKR_NO_EVENT: |
72 | 0 | case CKR_FUNCTION_NOT_PARALLEL: |
73 | 0 | case CKR_SESSION_PARALLEL_NOT_SUPPORTED: |
74 | 0 | return ""; |
75 | | |
76 | 0 | case CKR_CANCEL: |
77 | 0 | case CKR_FUNCTION_CANCELED: |
78 | 0 | return _("The operation was cancelled"); |
79 | | |
80 | 0 | case CKR_HOST_MEMORY: |
81 | 0 | return _("Insufficient memory available"); |
82 | 0 | case CKR_SLOT_ID_INVALID: |
83 | 0 | return _("The specified slot ID is not valid"); |
84 | 0 | case CKR_GENERAL_ERROR: |
85 | 0 | return _("Internal error"); |
86 | 0 | case CKR_FUNCTION_FAILED: |
87 | 0 | return _("The operation failed"); |
88 | 0 | case CKR_ARGUMENTS_BAD: |
89 | 0 | return _("Invalid arguments"); |
90 | 0 | case CKR_NEED_TO_CREATE_THREADS: |
91 | 0 | return _("The module cannot create needed threads"); |
92 | 0 | case CKR_CANT_LOCK: |
93 | 0 | return _("The module cannot lock data properly"); |
94 | 0 | case CKR_ATTRIBUTE_READ_ONLY: |
95 | 0 | return _("The field is read-only"); |
96 | 0 | case CKR_ATTRIBUTE_SENSITIVE: |
97 | 0 | return _("The field is sensitive and cannot be revealed"); |
98 | 0 | case CKR_ATTRIBUTE_TYPE_INVALID: |
99 | 0 | return _("The field is invalid or does not exist"); |
100 | 0 | case CKR_ATTRIBUTE_VALUE_INVALID: |
101 | 0 | return _("Invalid value for field"); |
102 | 0 | case CKR_DATA_INVALID: |
103 | 0 | return _("The data is not valid or unrecognized"); |
104 | 0 | case CKR_DATA_LEN_RANGE: |
105 | 0 | return _("The data is too long"); |
106 | 0 | case CKR_DEVICE_ERROR: |
107 | 0 | return _("An error occurred on the device"); |
108 | 0 | case CKR_DEVICE_MEMORY: |
109 | 0 | return _("Insufficient memory available on the device"); |
110 | 0 | case CKR_DEVICE_REMOVED: |
111 | 0 | return _("The device was removed or unplugged"); |
112 | 0 | case CKR_ENCRYPTED_DATA_INVALID: |
113 | 0 | return _("The encrypted data is not valid or unrecognized"); |
114 | 0 | case CKR_ENCRYPTED_DATA_LEN_RANGE: |
115 | 0 | return _("The encrypted data is too long"); |
116 | 0 | case CKR_FUNCTION_NOT_SUPPORTED: |
117 | 0 | return _("This operation is not supported"); |
118 | 0 | case CKR_KEY_HANDLE_INVALID: |
119 | 0 | return _("The key is missing or invalid"); |
120 | 0 | case CKR_KEY_SIZE_RANGE: |
121 | 0 | return _("The key is the wrong size"); |
122 | 0 | case CKR_KEY_TYPE_INCONSISTENT: |
123 | 0 | return _("The key is of the wrong type"); |
124 | 0 | case CKR_KEY_NOT_NEEDED: |
125 | 0 | return _("No key is needed"); |
126 | 0 | case CKR_KEY_CHANGED: |
127 | 0 | return _("The key is different than before"); |
128 | 0 | case CKR_KEY_NEEDED: |
129 | 0 | return _("A key is needed"); |
130 | 0 | case CKR_KEY_INDIGESTIBLE: |
131 | 0 | return _("Cannot include the key in the digest"); |
132 | 0 | case CKR_KEY_FUNCTION_NOT_PERMITTED: |
133 | 0 | return _("This operation cannot be done with this key"); |
134 | 0 | case CKR_KEY_NOT_WRAPPABLE: |
135 | 0 | return _("The key cannot be wrapped"); |
136 | 0 | case CKR_KEY_UNEXTRACTABLE: |
137 | 0 | return _("Cannot export this key"); |
138 | 0 | case CKR_MECHANISM_INVALID: |
139 | 0 | return _("The crypto mechanism is invalid or unrecognized"); |
140 | 0 | case CKR_MECHANISM_PARAM_INVALID: |
141 | 0 | return _("The crypto mechanism has an invalid argument"); |
142 | 0 | case CKR_OBJECT_HANDLE_INVALID: |
143 | 0 | return _("The object is missing or invalid"); |
144 | 0 | case CKR_OPERATION_ACTIVE: |
145 | 0 | return _("Another operation is already taking place"); |
146 | 0 | case CKR_OPERATION_NOT_INITIALIZED: |
147 | 0 | return _("No operation is taking place"); |
148 | 0 | case CKR_PIN_INCORRECT: |
149 | 0 | return _("The password or PIN is incorrect"); |
150 | 0 | case CKR_PIN_INVALID: |
151 | 0 | return _("The password or PIN is invalid"); |
152 | 0 | case CKR_PIN_LEN_RANGE: |
153 | 0 | return _("The password or PIN is of an invalid length"); |
154 | 0 | case CKR_PIN_EXPIRED: |
155 | 0 | return _("The password or PIN has expired"); |
156 | 0 | case CKR_PIN_LOCKED: |
157 | 0 | return _("The password or PIN is locked"); |
158 | 0 | case CKR_SESSION_CLOSED: |
159 | 0 | return _("The session is closed"); |
160 | 0 | case CKR_SESSION_COUNT: |
161 | 0 | return _("Too many sessions are active"); |
162 | 0 | case CKR_SESSION_HANDLE_INVALID: |
163 | 0 | return _("The session is invalid"); |
164 | 0 | case CKR_SESSION_READ_ONLY: |
165 | 0 | return _("The session is read-only"); |
166 | 0 | case CKR_SESSION_EXISTS: |
167 | 0 | return _("An open session exists"); |
168 | 0 | case CKR_SESSION_READ_ONLY_EXISTS: |
169 | 0 | return _("A read-only session exists"); |
170 | 0 | case CKR_SESSION_READ_WRITE_SO_EXISTS: |
171 | 0 | return _("An administrator session exists"); |
172 | 0 | case CKR_SIGNATURE_INVALID: |
173 | 0 | return _("The signature is bad or corrupted"); |
174 | 0 | case CKR_SIGNATURE_LEN_RANGE: |
175 | 0 | return _("The signature is unrecognized or corrupted"); |
176 | 0 | case CKR_TEMPLATE_INCOMPLETE: |
177 | 0 | return _("Certain required fields are missing"); |
178 | 0 | case CKR_TEMPLATE_INCONSISTENT: |
179 | 0 | return _("Certain fields have invalid values"); |
180 | 0 | case CKR_TOKEN_NOT_PRESENT: |
181 | 0 | return _("The device is not present or unplugged"); |
182 | 0 | case CKR_TOKEN_NOT_RECOGNIZED: |
183 | 0 | return _("The device is invalid or unrecognizable"); |
184 | 0 | case CKR_TOKEN_WRITE_PROTECTED: |
185 | 0 | return _("The device is write protected"); |
186 | 0 | case CKR_UNWRAPPING_KEY_HANDLE_INVALID: |
187 | 0 | return _("Cannot import because the key is invalid"); |
188 | 0 | case CKR_UNWRAPPING_KEY_SIZE_RANGE: |
189 | 0 | return _("Cannot import because the key is of the wrong size"); |
190 | 0 | case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT: |
191 | 0 | return _("Cannot import because the key is of the wrong type"); |
192 | 0 | case CKR_USER_ALREADY_LOGGED_IN: |
193 | 0 | return _("You are already logged in"); |
194 | 0 | case CKR_USER_NOT_LOGGED_IN: |
195 | 0 | return _("No user has logged in"); |
196 | 0 | case CKR_USER_PIN_NOT_INITIALIZED: |
197 | 0 | return _("The user's password or PIN is not set"); |
198 | 0 | case CKR_USER_TYPE_INVALID: |
199 | 0 | return _("The user is of an invalid type"); |
200 | 0 | case CKR_USER_ANOTHER_ALREADY_LOGGED_IN: |
201 | 0 | return _("Another user is already logged in"); |
202 | 0 | case CKR_USER_TOO_MANY_TYPES: |
203 | 0 | return _("Too many users of different types are logged in"); |
204 | 0 | case CKR_WRAPPED_KEY_INVALID: |
205 | 0 | return _("Cannot import an invalid key"); |
206 | 0 | case CKR_WRAPPED_KEY_LEN_RANGE: |
207 | 0 | return _("Cannot import a key of the wrong size"); |
208 | 0 | case CKR_WRAPPING_KEY_HANDLE_INVALID: |
209 | 0 | return _("Cannot export because the key is invalid"); |
210 | 0 | case CKR_WRAPPING_KEY_SIZE_RANGE: |
211 | 0 | return _("Cannot export because the key is of the wrong size"); |
212 | 0 | case CKR_WRAPPING_KEY_TYPE_INCONSISTENT: |
213 | 0 | return _("Cannot export because the key is of the wrong type"); |
214 | 0 | case CKR_RANDOM_SEED_NOT_SUPPORTED: |
215 | 0 | return _("Unable to initialize the random number generator"); |
216 | 0 | case CKR_RANDOM_NO_RNG: |
217 | 0 | return _("No random number generator available"); |
218 | 0 | case CKR_DOMAIN_PARAMS_INVALID: |
219 | 0 | return _("The crypto mechanism has an invalid parameter"); |
220 | 0 | case CKR_BUFFER_TOO_SMALL: |
221 | 0 | return _("Not enough space to store the result"); |
222 | 0 | case CKR_SAVED_STATE_INVALID: |
223 | 0 | return _("The saved state is invalid"); |
224 | 0 | case CKR_INFORMATION_SENSITIVE: |
225 | 0 | return _("The information is sensitive and cannot be revealed"); |
226 | 0 | case CKR_STATE_UNSAVEABLE: |
227 | 0 | return _("The state cannot be saved"); |
228 | 0 | case CKR_CRYPTOKI_NOT_INITIALIZED: |
229 | 0 | return _("The module has not been initialized"); |
230 | 0 | case CKR_CRYPTOKI_ALREADY_INITIALIZED: |
231 | 0 | return _("The module has already been initialized"); |
232 | 0 | case CKR_MUTEX_BAD: |
233 | 0 | return _("Cannot lock data"); |
234 | 0 | case CKR_MUTEX_NOT_LOCKED: |
235 | 0 | return _("The data cannot be locked"); |
236 | 0 | case CKR_FUNCTION_REJECTED: |
237 | 0 | return _("The request was rejected by the user"); |
238 | | |
239 | 0 | default: |
240 | | return _("Unknown error"); |
241 | 0 | } |
242 | 0 | } |