~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/pk11wrap/pk11err.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is the Netscape security libraries.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Netscape
 
15
 * Communications Corporation.  Portions created by Netscape are 
 
16
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
17
 * Rights Reserved.
 
18
 * 
 
19
 * Contributor(s):
 
20
 * 
 
21
 * Alternatively, the contents of this file may be used under the
 
22
 * terms of the GNU General Public License Version 2 or later (the
 
23
 * "GPL"), in which case the provisions of the GPL are applicable 
 
24
 * instead of those above.  If you wish to allow use of your 
 
25
 * version of this file only under the terms of the GPL and not to
 
26
 * allow others to use your version of this file under the MPL,
 
27
 * indicate your decision by deleting the provisions above and
 
28
 * replace them with the notice and other provisions required by
 
29
 * the GPL.  If you do not delete the provisions above, a recipient
 
30
 * may use your version of this file under either the MPL or the
 
31
 * GPL.
 
32
 */
 
33
/* 
 
34
 * this file maps PKCS11 Errors into SECErrors
 
35
 *  This is an information reducing process, since most errors are reflected
 
36
 *  back to the user (the user doesn't care about invalid flags, or active
 
37
 *  operations). If any of these errors need more detail in the upper layers
 
38
 *  which call PK11 library functions, we can add more SEC_ERROR_XXX functions
 
39
 *  and change there mappings here.
 
40
 */
 
41
#include "pkcs11t.h"
 
42
#include "pk11func.h"
 
43
#include "secerr.h"
 
44
 
 
45
#ifdef PK11_ERROR_USE_ARRAY 
 
46
 
 
47
/*
 
48
 * build a static array of entries...
 
49
 */
 
50
static struct {
 
51
        CK_RV pk11_error;
 
52
        int   sec_error;
 
53
} pk11_error_map = {
 
54
#define MAPERROR(x,y) {x, y},
 
55
 
 
56
#else
 
57
 
 
58
/* the default is to use a big switch statement */
 
59
int
 
60
PK11_MapError(CK_RV rv) {
 
61
 
 
62
        switch (rv) {
 
63
#define MAPERROR(x,y) case x: return y;
 
64
 
 
65
#endif
 
66
 
 
67
/* the guts mapping */
 
68
        MAPERROR(CKR_OK, 0)
 
69
        MAPERROR(CKR_CANCEL, SEC_ERROR_IO)
 
70
        MAPERROR(CKR_HOST_MEMORY, SEC_ERROR_NO_MEMORY)
 
71
        MAPERROR(CKR_SLOT_ID_INVALID, SEC_ERROR_BAD_DATA)
 
72
        MAPERROR(CKR_ATTRIBUTE_READ_ONLY, SEC_ERROR_READ_ONLY)
 
73
        MAPERROR(CKR_ATTRIBUTE_SENSITIVE, SEC_ERROR_IO) /* XX SENSITIVE */
 
74
        MAPERROR(CKR_ATTRIBUTE_TYPE_INVALID, SEC_ERROR_BAD_DATA)
 
75
        MAPERROR(CKR_ATTRIBUTE_VALUE_INVALID, SEC_ERROR_BAD_DATA)
 
76
        MAPERROR(CKR_DATA_INVALID, SEC_ERROR_BAD_DATA)
 
77
        MAPERROR(CKR_DATA_LEN_RANGE, SEC_ERROR_BAD_DATA)
 
78
        MAPERROR(CKR_DEVICE_ERROR, SEC_ERROR_IO)
 
79
        MAPERROR(CKR_DEVICE_MEMORY, SEC_ERROR_NO_MEMORY)
 
80
        MAPERROR(CKR_DEVICE_REMOVED, SEC_ERROR_NO_TOKEN)
 
81
        MAPERROR(CKR_ENCRYPTED_DATA_INVALID, SEC_ERROR_BAD_DATA)
 
82
        MAPERROR(CKR_ENCRYPTED_DATA_LEN_RANGE, SEC_ERROR_BAD_DATA)
 
83
        MAPERROR(CKR_FUNCTION_CANCELED, SEC_ERROR_LIBRARY_FAILURE)
 
84
        MAPERROR(CKR_FUNCTION_NOT_PARALLEL, SEC_ERROR_LIBRARY_FAILURE)
 
85
        MAPERROR(CKR_KEY_HANDLE_INVALID, SEC_ERROR_INVALID_KEY)
 
86
        MAPERROR(CKR_KEY_SIZE_RANGE, SEC_ERROR_INVALID_KEY)
 
87
        MAPERROR(CKR_KEY_TYPE_INCONSISTENT, SEC_ERROR_INVALID_KEY)
 
88
        MAPERROR(CKR_MECHANISM_INVALID, SEC_ERROR_BAD_DATA)
 
89
        MAPERROR(CKR_MECHANISM_PARAM_INVALID, SEC_ERROR_BAD_DATA)
 
90
        MAPERROR(CKR_NO_EVENT, SEC_ERROR_NO_EVENT)
 
91
        MAPERROR(CKR_OBJECT_HANDLE_INVALID, SEC_ERROR_BAD_DATA)
 
92
        MAPERROR(CKR_OPERATION_ACTIVE, SEC_ERROR_LIBRARY_FAILURE)
 
93
        MAPERROR(CKR_OPERATION_NOT_INITIALIZED,SEC_ERROR_LIBRARY_FAILURE )
 
94
        MAPERROR(CKR_PIN_INCORRECT, SEC_ERROR_BAD_PASSWORD)
 
95
        MAPERROR(CKR_PIN_INVALID, SEC_ERROR_BAD_PASSWORD)
 
96
        MAPERROR(CKR_PIN_LEN_RANGE, SEC_ERROR_BAD_PASSWORD)
 
97
        MAPERROR(CKR_SESSION_CLOSED, SEC_ERROR_LIBRARY_FAILURE)
 
98
        MAPERROR(CKR_SESSION_COUNT, SEC_ERROR_NO_MEMORY) /* XXXX? */
 
99
        MAPERROR(CKR_SESSION_HANDLE_INVALID, SEC_ERROR_BAD_DATA)
 
100
        MAPERROR(CKR_SESSION_PARALLEL_NOT_SUPPORTED, SEC_ERROR_LIBRARY_FAILURE)
 
101
        MAPERROR(CKR_SESSION_READ_ONLY, SEC_ERROR_LIBRARY_FAILURE)
 
102
        MAPERROR(CKR_SIGNATURE_INVALID, SEC_ERROR_BAD_SIGNATURE)
 
103
        MAPERROR(CKR_SIGNATURE_LEN_RANGE, SEC_ERROR_BAD_SIGNATURE)
 
104
        MAPERROR(CKR_TEMPLATE_INCOMPLETE, SEC_ERROR_BAD_DATA)
 
105
        MAPERROR(CKR_TEMPLATE_INCONSISTENT, SEC_ERROR_BAD_DATA)
 
106
        MAPERROR(CKR_TOKEN_NOT_PRESENT, SEC_ERROR_NO_TOKEN)
 
107
        MAPERROR(CKR_TOKEN_NOT_RECOGNIZED, SEC_ERROR_IO)
 
108
        MAPERROR(CKR_TOKEN_WRITE_PROTECTED, SEC_ERROR_READ_ONLY)
 
109
        MAPERROR(CKR_UNWRAPPING_KEY_HANDLE_INVALID, SEC_ERROR_INVALID_KEY)
 
110
        MAPERROR(CKR_UNWRAPPING_KEY_SIZE_RANGE, SEC_ERROR_INVALID_KEY)
 
111
        MAPERROR(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT, SEC_ERROR_INVALID_KEY)
 
112
        MAPERROR(CKR_USER_ALREADY_LOGGED_IN, 0)
 
113
        MAPERROR(CKR_USER_NOT_LOGGED_IN, SEC_ERROR_LIBRARY_FAILURE) /* XXXX */
 
114
        MAPERROR(CKR_USER_PIN_NOT_INITIALIZED, SEC_ERROR_NO_TOKEN)
 
115
        MAPERROR(CKR_USER_TYPE_INVALID, SEC_ERROR_LIBRARY_FAILURE)
 
116
        MAPERROR(CKR_WRAPPED_KEY_INVALID, SEC_ERROR_INVALID_KEY)
 
117
        MAPERROR(CKR_WRAPPED_KEY_LEN_RANGE, SEC_ERROR_INVALID_KEY)
 
118
        MAPERROR(CKR_WRAPPING_KEY_HANDLE_INVALID, SEC_ERROR_INVALID_KEY)
 
119
        MAPERROR(CKR_WRAPPING_KEY_SIZE_RANGE, SEC_ERROR_INVALID_KEY)
 
120
        MAPERROR(CKR_WRAPPING_KEY_TYPE_INCONSISTENT, SEC_ERROR_INVALID_KEY)
 
121
        MAPERROR(CKR_VENDOR_DEFINED, SEC_ERROR_LIBRARY_FAILURE)
 
122
 
 
123
 
 
124
#ifdef PK11_ERROR_USE_ARRAY 
 
125
};
 
126
 
 
127
int
 
128
PK11_MapError(CK_RV rv) {
 
129
    int size = sizeof(pk11_error_map)/sizeof(pk11_error_map[0]);
 
130
 
 
131
    for (i=0; i < size; i++) {
 
132
        if (pk11_error_map[i].pk11_error == rv) {
 
133
            return pk11_error_map[i].sec_error;
 
134
        }
 
135
    }
 
136
    return SEC_ERROR_IO;
 
137
 }
 
138
 
 
139
 
 
140
#else
 
141
 
 
142
    default:
 
143
        break;
 
144
    }
 
145
    return SEC_ERROR_IO;
 
146
}
 
147
 
 
148
 
 
149
#endif