jdk/src/share/classes/javax/crypto/ExemptionMechanism.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8152 94e5966bdf22
child 18771 9dadb0719cea
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8152
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.crypto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.AlgorithmParameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.Key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.InvalidAlgorithmParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class provides the functionality of an exemption mechanism, examples
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of which are <i>key recovery</i>, <i>key weakening</i>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <i>key escrow</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>Applications or applets that use an exemption mechanism may be granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * stronger encryption capabilities than those which don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class ExemptionMechanism {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private ExemptionMechanismSpi exmechSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // The name of the exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private String mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // Flag which indicates whether this ExemptionMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // result is generated successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // State information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private boolean initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // Store away the key at init() time for later comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private Key keyStored = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Creates a ExemptionMechanism object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param exmechSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param mechanism the exemption mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected ExemptionMechanism(ExemptionMechanismSpi exmechSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                 Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                 String mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this.exmechSpi = exmechSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.mechanism = mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Returns the exemption mechanism name of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <p>This is the same name that was specified in one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <code>getInstance</code> calls that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return the exemption mechanism name of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return this.mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns an <code>ExemptionMechanism</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * specified exemption mechanism algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * A new ExemptionMechanism object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * ExemptionMechanismSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param algorithm the standard name of the requested exemption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * mechanism.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   117
     * See the ExemptionMechanism section in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <a href=
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   119
     *   "{docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   120
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * for information about standard exemption mechanism names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the new <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @exception NullPointerException if <code>algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @exception NoSuchAlgorithmException if no Provider supports an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *          ExemptionMechanismSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static final ExemptionMechanism getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Instance instance = JceSecurity.getInstance("ExemptionMechanism",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                ExemptionMechanismSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns an <code>ExemptionMechanism</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * specified exemption mechanism algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p> A new ExemptionMechanism object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * ExemptionMechanismSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param algorithm the standard name of the requested exemption mechanism.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   156
     * See the ExemptionMechanism section in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <a href=
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   158
     *   "{docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   159
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * for information about standard exemption mechanism names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the new <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @exception NullPointerException if <code>algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @exception NoSuchAlgorithmException if an ExemptionMechanismSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @exception IllegalArgumentException if the <code>provider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *          is null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public static final ExemptionMechanism getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Instance instance = JceSecurity.getInstance("ExemptionMechanism",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                ExemptionMechanismSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns an <code>ExemptionMechanism</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * specified exemption mechanism algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <p> A new ExemptionMechanism object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * ExemptionMechanismSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param algorithm the standard name of the requested exemption mechanism.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   200
     * See the ExemptionMechanism section in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <a href=
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   202
     *   "{docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   203
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * for information about standard exemption mechanism names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return the new <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @exception NullPointerException if <code>algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @exception NoSuchAlgorithmException if an ExemptionMechanismSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @exception IllegalArgumentException if the <code>provider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public static final ExemptionMechanism getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        Instance instance = JceSecurity.getInstance("ExemptionMechanism",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                ExemptionMechanismSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Returns the provider of this <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return the provider of this <code>ExemptionMechanism</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Returns whether the result blob has been generated successfully by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <p>The method also makes sure that the key passed in is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * the one this exemption mechanism used in initializing and generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * phases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param key the key the crypto is going to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return whether the result blob of the same key has been generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * successfully by this exemption mechanism; false if <code>key</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @exception ExemptionMechanismException if problem(s) encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * while determining whether the result blob has been generated successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * by this exemption mechanism object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public final boolean isCryptoAllowed(Key key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            throws ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        boolean ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (done && (key != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // Check if the key passed in is the same as the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // this exemption mechanism used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            ret = keyStored.equals(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns the length in bytes that an output buffer would need to be in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * order to hold the result of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * {@link #genExemptionBlob(byte[]) genExemptionBlob}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * operation, given the input length <code>inputLen</code> (in bytes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>The actual output length of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * {@link #genExemptionBlob(byte[]) genExemptionBlob}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * call may be smaller than the length returned by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param inputLen the input length (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return the required output buffer size (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @exception IllegalStateException if this exemption mechanism is in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * wrong state (e.g., has not yet been initialized)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public final int getOutputSize(int inputLen) throws IllegalStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                "ExemptionMechanism not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (inputLen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                "Input size must be equal to " + "or greater than zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return exmechSpi.engineGetOutputSize(inputLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Initializes this exemption mechanism with a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <p>If this exemption mechanism requires any algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * that cannot be derived from the given <code>key</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * underlying exemption mechanism implementation is supposed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * generate the required parameters itself (using provider-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * default values); in the case that algorithm parameters must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * specified by the caller, an <code>InvalidKeyException</code> is raised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param key the key for this exemption mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * this exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * process of initializing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public final void init(Key key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            throws InvalidKeyException, ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        keyStored = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        exmechSpi.engineInit(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Initializes this exemption mechanism with a key and a set of algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <p>If this exemption mechanism requires any algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * and <code>params</code> is null, the underlying exemption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * mechanism implementation is supposed to generate the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * parameters itself (using provider-specific default values); in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * that algorithm parameters must be specified by the caller, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <code>InvalidAlgorithmParameterException</code> is raised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param key the key for this exemption mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * this exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @exception InvalidAlgorithmParameterException if the given algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * parameters are inappropriate for this exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * process of initializing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public final void init(Key key, AlgorithmParameterSpec params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            throws InvalidKeyException, InvalidAlgorithmParameterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        keyStored = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        exmechSpi.engineInit(key, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Initializes this exemption mechanism with a key and a set of algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <p>If this exemption mechanism requires any algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * and <code>params</code> is null, the underlying exemption mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * implementation is supposed to generate the required parameters itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * (using provider-specific default values); in the case that algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * parameters must be specified by the caller, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <code>InvalidAlgorithmParameterException</code> is raised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param key the key for this exemption mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * this exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception InvalidAlgorithmParameterException if the given algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * parameters are inappropriate for this exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * process of initializing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public final void init(Key key, AlgorithmParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            throws InvalidKeyException, InvalidAlgorithmParameterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        keyStored = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        exmechSpi.engineInit(key, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Generates the exemption mechanism key blob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return the new buffer with the result key blob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception IllegalStateException if this exemption mechanism is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * a wrong state (e.g., has not been initialized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * process of generating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public final byte[] genExemptionBlob() throws IllegalStateException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                "ExemptionMechanism not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        byte[] blob = exmechSpi.engineGenExemptionBlob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return blob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Generates the exemption mechanism key blob, and stores the result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * the <code>output</code> buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>If the <code>output</code> buffer is too small to hold the result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * a <code>ShortBufferException</code> is thrown. In this case, repeat this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * call with a larger output buffer. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * {@link #getOutputSize(int) getOutputSize} to determine how big
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * the output buffer should be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param output the buffer for the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return the number of bytes stored in <code>output</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @exception IllegalStateException if this exemption mechanism is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * a wrong state (e.g., has not been initialized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @exception ShortBufferException if the given output buffer is too small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * to hold the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * process of generating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public final int genExemptionBlob(byte[] output)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            throws IllegalStateException, ShortBufferException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            throw new IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            ("ExemptionMechanism not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        int n = exmechSpi.engineGenExemptionBlob(output, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Generates the exemption mechanism key blob, and stores the result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * the <code>output</code> buffer, starting at <code>outputOffset</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <p>If the <code>output</code> buffer is too small to hold the result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * a <code>ShortBufferException</code> is thrown. In this case, repeat this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * call with a larger output buffer. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * {@link #getOutputSize(int) getOutputSize} to determine how big
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * the output buffer should be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param output the buffer for the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @param outputOffset the offset in <code>output</code> where the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @return the number of bytes stored in <code>output</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception IllegalStateException if this exemption mechanism is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * a wrong state (e.g., has not been initialized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception ShortBufferException if the given output buffer is too small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * to hold the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @exception ExemptionMechanismException if problem(s) encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * process of generating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public final int genExemptionBlob(byte[] output, int outputOffset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            throws IllegalStateException, ShortBufferException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            ExemptionMechanismException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            throw new IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            ("ExemptionMechanism not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        int n = exmechSpi.engineGenExemptionBlob(output, outputOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Ensures that the key stored away by this ExemptionMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * object will be wiped out when there are no more references to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        keyStored = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // Are there anything else we could do?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
}