jdk/src/share/classes/sun/security/x509/OIDMap.java
author jjg
Mon, 15 Aug 2011 11:48:20 -0700
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
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: 5506
diff changeset
     2
 * Copyright (c) 1997, 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: 2281
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: 2281
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: 2281
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2281
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2281
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 sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class defines the mapping from OID & name to classes and vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * versa.  Used by CertificateExtensions & PKCS10 to get the java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * classes associated with a particular OID/name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class OIDMap {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private OIDMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // "user-friendly" names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final String ROOT = X509CertImpl.NAME + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                 X509CertInfo.NAME + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                 X509CertInfo.EXTENSIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final String AUTH_KEY_IDENTIFIER = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                          AuthorityKeyIdentifierExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final String SUB_KEY_IDENTIFIER  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                          SubjectKeyIdentifierExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final String KEY_USAGE           = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                          KeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final String PRIVATE_KEY_USAGE   = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                          PrivateKeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final String POLICY_MAPPINGS     = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                          PolicyMappingsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final String SUB_ALT_NAME        = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                          SubjectAlternativeNameExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final String ISSUER_ALT_NAME     = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                          IssuerAlternativeNameExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final String BASIC_CONSTRAINTS   = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                          BasicConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final String NAME_CONSTRAINTS    = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                          NameConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final String POLICY_CONSTRAINTS  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                          PolicyConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final String CRL_NUMBER  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                              CRLNumberExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final String CRL_REASON  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                              CRLReasonCodeExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final String NETSCAPE_CERT  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                              NetscapeCertTypeExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final String CERT_POLICIES = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                             CertificatePoliciesExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final String EXT_KEY_USAGE       = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                          ExtendedKeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final String INHIBIT_ANY_POLICY  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                          InhibitAnyPolicyExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final String CRL_DIST_POINTS = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                        CRLDistributionPointsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final String CERT_ISSUER = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                        CertificateIssuerExtension.NAME;
2067
6f9db5f305cd 6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents: 2
diff changeset
    92
    private static final String SUBJECT_INFO_ACCESS = ROOT + "." +
6f9db5f305cd 6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents: 2
diff changeset
    93
                                          SubjectInfoAccessExtension.NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final String AUTH_INFO_ACCESS = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                          AuthorityInfoAccessExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static final String ISSUING_DIST_POINT = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                        IssuingDistributionPointExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String DELTA_CRL_INDICATOR = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                        DeltaCRLIndicatorExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final String FRESHEST_CRL = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                        FreshestCRLExtension.NAME;
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 2067
diff changeset
   102
    private static final String OCSPNOCHECK = ROOT + "." +
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 2067
diff changeset
   103
                                        OCSPNoCheckExtension.NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final int NetscapeCertType_data[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        { 2, 16, 840, 1, 113730, 1, 1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /** Map ObjectIdentifier(oid) -> OIDInfo(info) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private final static Map<ObjectIdentifier,OIDInfo> oidMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /** Map String(friendly name) -> OIDInfo(info) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private final static Map<String,OIDInfo> nameMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        oidMap = new HashMap<ObjectIdentifier,OIDInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        nameMap = new HashMap<String,OIDInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        addInternal(SUB_KEY_IDENTIFIER, PKIXExtensions.SubjectKey_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    "sun.security.x509.SubjectKeyIdentifierExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        addInternal(KEY_USAGE, PKIXExtensions.KeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    "sun.security.x509.KeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        addInternal(PRIVATE_KEY_USAGE, PKIXExtensions.PrivateKeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    "sun.security.x509.PrivateKeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        addInternal(SUB_ALT_NAME, PKIXExtensions.SubjectAlternativeName_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    "sun.security.x509.SubjectAlternativeNameExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        addInternal(ISSUER_ALT_NAME, PKIXExtensions.IssuerAlternativeName_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    "sun.security.x509.IssuerAlternativeNameExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        addInternal(BASIC_CONSTRAINTS, PKIXExtensions.BasicConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    "sun.security.x509.BasicConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        addInternal(CRL_NUMBER, PKIXExtensions.CRLNumber_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    "sun.security.x509.CRLNumberExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        addInternal(CRL_REASON, PKIXExtensions.ReasonCode_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    "sun.security.x509.CRLReasonCodeExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        addInternal(NAME_CONSTRAINTS, PKIXExtensions.NameConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    "sun.security.x509.NameConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        addInternal(POLICY_MAPPINGS, PKIXExtensions.PolicyMappings_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    "sun.security.x509.PolicyMappingsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        addInternal(AUTH_KEY_IDENTIFIER, PKIXExtensions.AuthorityKey_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    "sun.security.x509.AuthorityKeyIdentifierExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        addInternal(POLICY_CONSTRAINTS, PKIXExtensions.PolicyConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    "sun.security.x509.PolicyConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        addInternal(NETSCAPE_CERT, ObjectIdentifier.newInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    (new int[] {2,16,840,1,113730,1,1}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    "sun.security.x509.NetscapeCertTypeExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        addInternal(CERT_POLICIES, PKIXExtensions.CertificatePolicies_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    "sun.security.x509.CertificatePoliciesExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        addInternal(EXT_KEY_USAGE, PKIXExtensions.ExtendedKeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    "sun.security.x509.ExtendedKeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        addInternal(INHIBIT_ANY_POLICY, PKIXExtensions.InhibitAnyPolicy_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    "sun.security.x509.InhibitAnyPolicyExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        addInternal(CRL_DIST_POINTS, PKIXExtensions.CRLDistributionPoints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    "sun.security.x509.CRLDistributionPointsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        addInternal(CERT_ISSUER, PKIXExtensions.CertificateIssuer_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    "sun.security.x509.CertificateIssuerExtension");
2067
6f9db5f305cd 6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents: 2
diff changeset
   154
        addInternal(SUBJECT_INFO_ACCESS, PKIXExtensions.SubjectInfoAccess_Id,
6f9db5f305cd 6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents: 2
diff changeset
   155
                    "sun.security.x509.SubjectInfoAccessExtension");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        addInternal(AUTH_INFO_ACCESS, PKIXExtensions.AuthInfoAccess_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    "sun.security.x509.AuthorityInfoAccessExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        addInternal(ISSUING_DIST_POINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    PKIXExtensions.IssuingDistributionPoint_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    "sun.security.x509.IssuingDistributionPointExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        addInternal(DELTA_CRL_INDICATOR, PKIXExtensions.DeltaCRLIndicator_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    "sun.security.x509.DeltaCRLIndicatorExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        addInternal(FRESHEST_CRL, PKIXExtensions.FreshestCRL_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    "sun.security.x509.FreshestCRLExtension");
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 2067
diff changeset
   165
        addInternal(OCSPNOCHECK, PKIXExtensions.OCSPNoCheck_Id,
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 2067
diff changeset
   166
                    "sun.security.x509.OCSPNoCheckExtension");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Add attributes to the table. For internal use in the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static void addInternal(String name, ObjectIdentifier oid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        OIDInfo info = new OIDInfo(name, oid, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        oidMap.put(oid, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        nameMap.put(name, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Inner class encapsulating the mapping info and Class loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private static class OIDInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        final ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        final String className;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   188
        private volatile Class<?> clazz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        OIDInfo(String name, ObjectIdentifier oid, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   196
        OIDInfo(String name, ObjectIdentifier oid, Class<?> clazz) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            this.className = clazz.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            this.clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * Return the Class object associated with this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   206
        Class<?> getClazz() throws CertificateException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   208
                Class<?> c = clazz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    c = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    clazz = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            } catch (ClassNotFoundException e) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   215
                throw new CertificateException("Could not load class: " + e, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Add a name to lookup table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param name the name of the attr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param oid the string representation of the object identifier for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *         the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param clazz the Class object associated with this attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @exception CertificateException on errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   229
    public static void addAttribute(String name, String oid, Class<?> clazz)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        ObjectIdentifier objId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            objId = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw new CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                ("Invalid Object identifier: " + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        OIDInfo info = new OIDInfo(name, objId, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (oidMap.put(objId, info) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                ("Object identifier already exists: " + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (nameMap.put(name, info) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throw new CertificateException("Name already exists: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Return user friendly name associated with the OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param oid the name of the object identifier to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return the user friendly name or null if no name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * is registered for this oid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public static String getName(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        OIDInfo info = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return (info == null) ? null : info.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Return Object identifier for user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param name the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return the Object Identifier or null if no oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * is registered for this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public static ObjectIdentifier getOID(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        OIDInfo info = nameMap.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return (info == null) ? null : info.oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Return the java class object associated with the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param name the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @exception CertificateException if class cannot be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   278
    public static Class<?> getClass(String name) throws CertificateException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        OIDInfo info = nameMap.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return (info == null) ? null : info.getClazz();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Return the java class object associated with the object identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param oid the name of the object identifier to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @exception CertificateException if class cannot be instatiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   289
    public static Class<?> getClass(ObjectIdentifier oid)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        OIDInfo info = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return (info == null) ? null : info.getClazz();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}