src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/UcryptoException.java
author apetcher
Tue, 23 Jan 2018 11:18:11 -0500
changeset 49789 27b359322b1e
parent 47216 71c04702a3d5
child 49793 a73fcbe66a57
permissions -rw-r--r--
8193409: Improve AES supporting classes Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     1
/*
49789
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     4
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    10
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    15
 * accompanied this code).
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    16
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    20
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    23
 * questions.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    24
 */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    25
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    26
package com.oracle.security.ucrypto;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    27
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    28
import java.util.*;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    29
import java.security.ProviderException;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    30
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    31
/**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    32
 * The exception class used by SunUcrypto provider. An exception
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    33
 * object of this class indicates that a function call to the underlying
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    34
 * native calls returned a value not equal to CRYPTO_SUCCESS.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    35
 *
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 31538
diff changeset
    36
 * @since 9
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    37
 */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    38
public final class UcryptoException extends ProviderException {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    39
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    40
    private static final long serialVersionUID = -933864511110035746L;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    41
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    42
    // NOTE: check /usr/include/sys/crypto/common.h for updates
49789
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    43
    public enum Error {
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    44
        CRYPTO_SUCCESS,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    45
        CRYPTO_CANCEL,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    46
        CRYPTO_HOST_MEMORY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    47
        CRYPTO_GENERAL_ERROR,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    48
        CRYPTO_FAILED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    49
        CRYPTO_ARGUMENTS_BAD,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    50
        CRYPTO_ATTRIBUTE_READ_ONLY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    51
        CRYPTO_ATTRIBUTE_SENSITIVE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    52
        CRYPTO_ATTRIBUTE_TYPE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    53
        CRYPTO_ATTRIBUTE_VALUE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    54
        CRYPTO_CANCELED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    55
        CRYPTO_DATA_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    56
        CRYPTO_DATA_LEN_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    57
        CRYPTO_DEVICE_ERROR,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    58
        CRYPTO_DEVICE_MEMORY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    59
        CRYPTO_DEVICE_REMOVED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    60
        CRYPTO_ENCRYPTED_DATA_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    61
        CRYPTO_ENCRYPTED_DATA_LEN_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    62
        CRYPTO_KEY_HANDLE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    63
        CRYPTO_KEY_SIZE_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    64
        CRYPTO_KEY_TYPE_INCONSISTENT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    65
        CRYPTO_KEY_NOT_NEEDED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    66
        CRYPTO_KEY_CHANGED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    67
        CRYPTO_KEY_NEEDED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    68
        CRYPTO_KEY_INDIGESTIBLE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    69
        CRYPTO_KEY_FUNCTION_NOT_PERMITTED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    70
        CRYPTO_KEY_NOT_WRAPPABLE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    71
        CRYPTO_KEY_UNEXTRACTABLE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    72
        CRYPTO_MECHANISM_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    73
        CRYPTO_MECHANISM_PARAM_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    74
        CRYPTO_OBJECT_HANDLE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    75
        CRYPTO_OPERATION_IS_ACTIVE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    76
        CRYPTO_OPERATION_NOT_INITIALIZED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    77
        CRYPTO_PIN_INCORRECT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    78
        CRYPTO_PIN_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    79
        CRYPTO_PIN_LEN_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    80
        CRYPTO_PIN_EXPIRED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    81
        CRYPTO_PIN_LOCKED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    82
        CRYPTO_SESSION_CLOSED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    83
        CRYPTO_SESSION_COUNT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    84
        CRYPTO_SESSION_HANDLE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    85
        CRYPTO_SESSION_READ_ONLY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    86
        CRYPTO_SESSION_EXISTS,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    87
        CRYPTO_SESSION_READ_ONLY_EXISTS,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    88
        CRYPTO_SESSION_READ_WRITE_SO_EXISTS,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    89
        CRYPTO_SIGNATURE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    90
        CRYPTO_SIGNATURE_LEN_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    91
        CRYPTO_TEMPLATE_INCOMPLETE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    92
        CRYPTO_TEMPLATE_INCONSISTENT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    93
        CRYPTO_UNWRAPPING_KEY_HANDLE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    94
        CRYPTO_UNWRAPPING_KEY_SIZE_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    95
        CRYPTO_UNWRAPPING_KEY_TYPE_INCONSISTENT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    96
        CRYPTO_USER_ALREADY_LOGGED_IN,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    97
        CRYPTO_USER_NOT_LOGGED_IN,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    98
        CRYPTO_USER_PIN_NOT_INITIALIZED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
    99
        CRYPTO_USER_TYPE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   100
        CRYPTO_USER_ANOTHER_ALREADY_LOGGED_IN,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   101
        CRYPTO_USER_TOO_MANY_TYPES,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   102
        CRYPTO_WRAPPED_KEY_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   103
        CRYPTO_WRAPPED_KEY_LEN_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   104
        CRYPTO_WRAPPING_KEY_HANDLE_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   105
        CRYPTO_WRAPPING_KEY_SIZE_RANGE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   106
        CRYPTO_WRAPPING_KEY_TYPE_INCONSISTENT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   107
        CRYPTO_RANDOM_SEED_NOT_SUPPORTED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   108
        CRYPTO_RANDOM_NO_RNG,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   109
        CRYPTO_DOMAIN_PARAMS_INVALID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   110
        CRYPTO_BUFFER_TOO_SMALL,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   111
        CRYPTO_INFORMATION_SENSITIVE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   112
        CRYPTO_NOT_SUPPORTED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   113
        CRYPTO_QUEUED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   114
        CRYPTO_BUFFER_TOO_BIG,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   115
        CRYPTO_INVALID_CONTEXT,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   116
        CRYPTO_INVALID_MAC,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   117
        CRYPTO_MECH_NOT_SUPPORTED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   118
        CRYPTO_INCONSISTENT_ATTRIBUTE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   119
        CRYPTO_NO_PERMISSION,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   120
        CRYPTO_INVALID_PROVIDER_ID,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   121
        CRYPTO_VERSION_MISMATCH,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   122
        CRYPTO_BUSY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   123
        CRYPTO_UNKNOWN_PROVIDER,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   124
        CRYPTO_MODVERIFICATION_FAILED,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   125
        CRYPTO_OLD_CTX_TEMPLATE,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   126
        CRYPTO_WEAK_KEY,
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   127
        CRYPTO_FIPS140_ERROR;
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   128
    };
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   129
49789
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   130
    // Array used to look up error by ordinal
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   131
    private static final Error[] ALL_ERRORS = Error.values();
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   132
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   133
    /**
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   134
     * Get the error enum value (if any) associated with this exception.
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   135
     */
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   136
    public Error getError() {
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   137
        return errorCode < ALL_ERRORS.length ?
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   138
            ALL_ERRORS[errorCode] :
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   139
            null;
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   140
    }
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   141
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   142
    /**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   143
     * The error code if this exception is triggered by a Ucrypto error.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   144
     */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   145
    private final int errorCode;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   146
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   147
    /**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   148
     * This method gets the corresponding text error message from a
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   149
     * predefined mapping. If mapping is not found, then it returns the error
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   150
     * code as a hex-string.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   151
     *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   152
     * @return The message or the error code; e.g. "CRYPTO_DATA_INVALID" or
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   153
     *         "0x88".
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   154
     */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   155
    static String getErrorMessage(int errorCode) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   156
        String message;
49789
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   157
        if (errorCode < ALL_ERRORS.length) {
27b359322b1e 8193409: Improve AES supporting classes
apetcher
parents: 47216
diff changeset
   158
            message = ALL_ERRORS[errorCode].name();
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   159
        } else {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   160
            message = "0x" + Integer.toHexString(errorCode);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   161
        }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   162
        return message;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   163
    }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   164
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   165
    /**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   166
     * Constructor taking the error code as defined for the CRYPTO_* constants
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   167
     */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   168
    public UcryptoException(int rv) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   169
        super(getErrorMessage(rv));
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   170
        this.errorCode = rv;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   171
    }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   172
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   173
    public UcryptoException(String message) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   174
        super(message);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   175
        errorCode = -1;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   176
    }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   177
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   178
    public UcryptoException(String message, Throwable cause) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   179
        super(message, cause);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   180
        errorCode = -1;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   181
    }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   183
    /**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   184
     * Returns the Ucrypto error code.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   185
     *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   186
     * @return The error code.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   187
     */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   188
    public int getErrorCode() {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   189
        return errorCode;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   190
    }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   191
}