jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java
author jjg
Mon, 15 Aug 2011 11:48:20 -0700
changeset 10336 0bb1999251f8
parent 7668 d4a77089c587
permissions -rw-r--r--
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror Reviewed-by: xuelei, mullan Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7668
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
package sun.security.pkcs11.wrapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * This is the superclass of all checked exceptions used by this package. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * exception of this class indicates that a function call to the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * PKCS#11 module returned a value not equal to CKR_OK. The application can get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the returned value by calling getErrorCode(). A return value not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * CKR_OK is the only reason for such an exception to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * PKCS#11 defines the meaning of an error-code, which may depend on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * context in which the error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @author <a href="mailto:Karl.Scheibelhofer@iaik.at"> Karl Scheibelhofer </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @invariants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public class PKCS11Exception extends Exception {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7668
diff changeset
    66
    private static final long serialVersionUID = 4877072363729195L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The code of the error which was the reason for this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected long errorCode_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final Map<Long,String> errorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        int[] errorCodes = new int[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            0x00000000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            0x00000001,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            0x00000002,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            0x00000003,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            0x00000005,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            0x00000006,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            0x00000007,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            0x00000008,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            0x00000009,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            0x0000000A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            0x00000010,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            0x00000011,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            0x00000012,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            0x00000013,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            0x00000020,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            0x00000021,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            0x00000030,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            0x00000031,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            0x00000032,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            0x00000040,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            0x00000041,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            0x00000050,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            0x00000051,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            0x00000054,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            0x00000060,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            0x00000062,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            0x00000063,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            0x00000064,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            0x00000065,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            0x00000066,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            0x00000067,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            0x00000068,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            0x00000069,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            0x0000006A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            0x00000070,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            0x00000071,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            0x00000082,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            0x00000090,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            0x00000091,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            0x000000A0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            0x000000A1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            0x000000A2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            0x000000A3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            0x000000A4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            0x000000B0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            0x000000B1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            0x000000B3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            0x000000B4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            0x000000B5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            0x000000B6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            0x000000B7,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            0x000000B8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            0x000000C0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            0x000000C1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            0x000000D0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            0x000000D1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            0x000000E0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            0x000000E1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            0x000000E2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            0x000000F0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            0x000000F1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            0x000000F2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            0x00000100,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            0x00000101,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            0x00000102,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            0x00000103,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            0x00000104,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            0x00000105,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            0x00000110,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            0x00000112,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            0x00000113,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            0x00000114,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            0x00000115,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            0x00000120,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            0x00000121,
5298
fbe659f73cfd 6944361: Missing CKR_ values in PKCS11Exception
andrew
parents: 2
diff changeset
   152
            0x00000130,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            0x00000150,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            0x00000160,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            0x00000170,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            0x00000180,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            0x00000190,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            0x00000191,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            0x000001A0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            0x000001A1,
5298
fbe659f73cfd 6944361: Missing CKR_ values in PKCS11Exception
andrew
parents: 2
diff changeset
   161
            0x00000200,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            0x80000000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        String[] errorMessages = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            "CKR_OK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            "CKR_CANCEL",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            "CKR_HOST_MEMORY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            "CKR_SLOT_ID_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            "CKR_GENERAL_ERROR",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            "CKR_FUNCTION_FAILED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            "CKR_ARGUMENTS_BAD",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            "CKR_NO_EVENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            "CKR_NEED_TO_CREATE_THREADS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            "CKR_CANT_LOCK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            "CKR_ATTRIBUTE_READ_ONLY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            "CKR_ATTRIBUTE_SENSITIVE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            "CKR_ATTRIBUTE_TYPE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            "CKR_ATTRIBUTE_VALUE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            "CKR_DATA_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            "CKR_DATA_LEN_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            "CKR_DEVICE_ERROR",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            "CKR_DEVICE_MEMORY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            "CKR_DEVICE_REMOVED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            "CKR_ENCRYPTED_DATA_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            "CKR_ENCRYPTED_DATA_LEN_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            "CKR_FUNCTION_CANCELED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            "CKR_FUNCTION_NOT_PARALLEL",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            "CKR_FUNCTION_NOT_SUPPORTED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            "CKR_KEY_HANDLE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            "CKR_KEY_SIZE_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            "CKR_KEY_TYPE_INCONSISTENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            "CKR_KEY_NOT_NEEDED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            "CKR_KEY_CHANGED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            "CKR_KEY_NEEDED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            "CKR_KEY_INDIGESTIBLE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            "CKR_KEY_FUNCTION_NOT_PERMITTED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            "CKR_KEY_NOT_WRAPPABLE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            "CKR_KEY_UNEXTRACTABLE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            "CKR_MECHANISM_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            "CKR_MECHANISM_PARAM_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            "CKR_OBJECT_HANDLE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            "CKR_OPERATION_ACTIVE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            "CKR_OPERATION_NOT_INITIALIZED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            "CKR_PIN_INCORRECT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            "CKR_PIN_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            "CKR_PIN_LEN_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            "CKR_PIN_EXPIRED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            "CKR_PIN_LOCKED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            "CKR_SESSION_CLOSED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            "CKR_SESSION_COUNT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            "CKR_SESSION_HANDLE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            "CKR_SESSION_PARALLEL_NOT_SUPPORTED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            "CKR_SESSION_READ_ONLY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            "CKR_SESSION_EXISTS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            "CKR_SESSION_READ_ONLY_EXISTS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            "CKR_SESSION_READ_WRITE_SO_EXISTS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            "CKR_SIGNATURE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            "CKR_SIGNATURE_LEN_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            "CKR_TEMPLATE_INCOMPLETE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            "CKR_TEMPLATE_INCONSISTENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            "CKR_TOKEN_NOT_PRESENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            "CKR_TOKEN_NOT_RECOGNIZED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            "CKR_TOKEN_WRITE_PROTECTED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            "CKR_UNWRAPPING_KEY_HANDLE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            "CKR_UNWRAPPING_KEY_SIZE_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            "CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            "CKR_USER_ALREADY_LOGGED_IN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            "CKR_USER_NOT_LOGGED_IN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            "CKR_USER_PIN_NOT_INITIALIZED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            "CKR_USER_TYPE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            "CKR_USER_ANOTHER_ALREADY_LOGGED_IN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            "CKR_USER_TOO_MANY_TYPES",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            "CKR_WRAPPED_KEY_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            "CKR_WRAPPED_KEY_LEN_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            "CKR_WRAPPING_KEY_HANDLE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            "CKR_WRAPPING_KEY_SIZE_RANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            "CKR_WRAPPING_KEY_TYPE_INCONSISTENT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            "CKR_RANDOM_SEED_NOT_SUPPORTED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            "CKR_RANDOM_NO_RNG",
5298
fbe659f73cfd 6944361: Missing CKR_ values in PKCS11Exception
andrew
parents: 2
diff changeset
   240
            "CKR_DOMAIN_PARAMS_INVALID",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            "CKR_BUFFER_TOO_SMALL",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            "CKR_SAVED_STATE_INVALID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            "CKR_INFORMATION_SENSITIVE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            "CKR_STATE_UNSAVEABLE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            "CKR_CRYPTOKI_NOT_INITIALIZED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            "CKR_CRYPTOKI_ALREADY_INITIALIZED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            "CKR_MUTEX_BAD",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            "CKR_MUTEX_NOT_LOCKED",
5298
fbe659f73cfd 6944361: Missing CKR_ values in PKCS11Exception
andrew
parents: 2
diff changeset
   249
            "CKR_FUNCTION_REJECTED",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            "CKR_VENDOR_DEFINED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        errorMap = new HashMap<Long,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        for (int i = 0; i < errorCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            errorMap.put(Long.valueOf(errorCodes[i]), errorMessages[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Constructor taking the error code as defined for the CKR_* constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * in PKCS#11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public PKCS11Exception(long errorCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        errorCode_ = errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * This method gets the corresponding text error message from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * a property file. If this file is not available, it returns the error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * code as a hex-string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return The message or the error code; e.g. "CKR_DEVICE_ERROR" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *         "0x00000030".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @preconditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @postconditions (result <> null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        String message = errorMap.get(Long.valueOf(errorCode_));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (message == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            message = "0x" + Functions.toFullHexString((int)errorCode_);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns the PKCS#11 error code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return The error code; e.g. 0x00000030.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @preconditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @postconditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public long getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return errorCode_ ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
}