jdk/src/java.base/share/classes/java/security/KeyFactorySpi.java
author sherman
Tue, 10 May 2016 21:19:25 -0700
changeset 37882 e7f3cf12e739
parent 25859 3317bb8137f4
permissions -rw-r--r--
6328855: String: Matches hangs at short and easy Strings containing \r \n 6192895: java.util.regex.Matcher: Performance issue 6345469: java.util.regex.Matcher utilizes 100% of the CPU 6988218: RegEx matcher loops 6693451: RegEx matcher goes into infinite delay 7006761: Matcher.matches() has infinite loop 8140212: Slow performance of Matcher.find 8151481: j.u.regex.Pattern cleanup 6609854: Regex does not match correctly for negative nested character classes 4916384: CANON_EQ supports only combining character sequences with non-spacing marks 4867170: Pattern doesn't work with composite character in CANON_EQ mode 6995635: CANON_EQ pattern flag is buggy 6728861: ExceptionInInitializerError is caught when the pattern has precomposed character 6736245: A character in Composition Exclusion Table does not match itself 7080302: the normalization in java regex pattern may have flaw Reviewed-by: rriggs, okutsu, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2013, 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 java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.spec.KeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.spec.InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    33
 * for the {@code KeyFactory} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * All the abstract methods in this class must be implemented by each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * cryptographic service provider who wishes to supply the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * of a key factory for a particular algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P> Key factories are used to convert <I>keys</I> (opaque
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    39
 * cryptographic keys of type {@code Key}) into <I>key specifications</I>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * (transparent representations of the underlying key material), and vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P> Key factories are bi-directional. That is, they allow you to build an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * opaque key object from a given key specification (key material), or to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * retrieve the underlying key material of a key object in a suitable format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P> Multiple compatible key specifications may exist for the same key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * For example, a DSA public key may be specified using
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    49
 * {@code DSAPublicKeySpec} or
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    50
 * {@code X509EncodedKeySpec}. A key factory can be used to translate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * between compatible key specifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <P> A provider should document all the key specifications supported by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see KeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see PublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see PrivateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see java.security.spec.KeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see java.security.spec.DSAPublicKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see java.security.spec.X509EncodedKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public abstract class KeyFactorySpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Generates a public key object from the provided key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * specification (key material).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param keySpec the specification (key material) of the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @exception InvalidKeySpecException if the given key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * is inappropriate for this key factory to produce a public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected abstract PublicKey engineGeneratePublic(KeySpec keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        throws InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Generates a private key object from the provided key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * specification (key material).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param keySpec the specification (key material) of the private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @return the private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @exception InvalidKeySpecException if the given key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * is inappropriate for this key factory to produce a private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        throws InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns a specification (key material) of the given key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * object.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   103
     * {@code keySpec} identifies the specification class in which
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * the key material should be returned. It could, for example, be
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   105
     * {@code DSAPublicKeySpec.class}, to indicate that the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * key material should be returned in an instance of the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   107
     * {@code DSAPublicKeySpec} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
19828
b4f91bc595fe 8024432: Fix doclint issues in java.security
juh
parents: 18579
diff changeset
   109
     * @param <T> the type of the key specification to be returned
b4f91bc595fe 8024432: Fix doclint issues in java.security
juh
parents: 18579
diff changeset
   110
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param key the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param keySpec the specification class in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * the key material should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return the underlying key specification (key material) in an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * of the requested specification class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @exception InvalidKeySpecException if the requested key specification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * inappropriate for the given key, or the given key cannot be dealt with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * (e.g., the given key has an unrecognized format).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected abstract <T extends KeySpec>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        T engineGetKeySpec(Key key, Class<T> keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        throws InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Translates a key object, whose provider may be unknown or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * potentially untrusted, into a corresponding key object of this key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param key the key whose provider is unknown or untrusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the translated key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception InvalidKeyException if the given key cannot be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * by this key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected abstract Key engineTranslateKey(Key key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        throws InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}