jdk/src/share/classes/sun/security/x509/OIDMap.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2067 6f9db5f305cd
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
import java.security.cert.CertificateParsingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class defines the mapping from OID & name to classes and vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * versa.  Used by CertificateExtensions & PKCS10 to get the java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * classes associated with a particular OID/name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class OIDMap {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private OIDMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // "user-friendly" names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final String ROOT = X509CertImpl.NAME + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                 X509CertInfo.NAME + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                 X509CertInfo.EXTENSIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final String AUTH_KEY_IDENTIFIER = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                          AuthorityKeyIdentifierExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final String SUB_KEY_IDENTIFIER  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                          SubjectKeyIdentifierExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final String KEY_USAGE           = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                          KeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final String PRIVATE_KEY_USAGE   = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                          PrivateKeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final String POLICY_MAPPINGS     = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                          PolicyMappingsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final String SUB_ALT_NAME        = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                          SubjectAlternativeNameExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final String ISSUER_ALT_NAME     = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                          IssuerAlternativeNameExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final String BASIC_CONSTRAINTS   = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                          BasicConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final String NAME_CONSTRAINTS    = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                          NameConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final String POLICY_CONSTRAINTS  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                          PolicyConstraintsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final String CRL_NUMBER  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                              CRLNumberExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final String CRL_REASON  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                              CRLReasonCodeExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final String NETSCAPE_CERT  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                              NetscapeCertTypeExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final String CERT_POLICIES = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                             CertificatePoliciesExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final String EXT_KEY_USAGE       = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                          ExtendedKeyUsageExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final String INHIBIT_ANY_POLICY  = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                          InhibitAnyPolicyExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final String CRL_DIST_POINTS = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                        CRLDistributionPointsExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final String CERT_ISSUER = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                        CertificateIssuerExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final String AUTH_INFO_ACCESS = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                          AuthorityInfoAccessExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final String ISSUING_DIST_POINT = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                        IssuingDistributionPointExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String DELTA_CRL_INDICATOR = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                        DeltaCRLIndicatorExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final String FRESHEST_CRL = ROOT + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                        FreshestCRLExtension.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final int NetscapeCertType_data[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        { 2, 16, 840, 1, 113730, 1, 1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /** Map ObjectIdentifier(oid) -> OIDInfo(info) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private final static Map<ObjectIdentifier,OIDInfo> oidMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /** Map String(friendly name) -> OIDInfo(info) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private final static Map<String,OIDInfo> nameMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        oidMap = new HashMap<ObjectIdentifier,OIDInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        nameMap = new HashMap<String,OIDInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        addInternal(SUB_KEY_IDENTIFIER, PKIXExtensions.SubjectKey_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    "sun.security.x509.SubjectKeyIdentifierExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        addInternal(KEY_USAGE, PKIXExtensions.KeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    "sun.security.x509.KeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        addInternal(PRIVATE_KEY_USAGE, PKIXExtensions.PrivateKeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    "sun.security.x509.PrivateKeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        addInternal(SUB_ALT_NAME, PKIXExtensions.SubjectAlternativeName_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    "sun.security.x509.SubjectAlternativeNameExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        addInternal(ISSUER_ALT_NAME, PKIXExtensions.IssuerAlternativeName_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    "sun.security.x509.IssuerAlternativeNameExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        addInternal(BASIC_CONSTRAINTS, PKIXExtensions.BasicConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    "sun.security.x509.BasicConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        addInternal(CRL_NUMBER, PKIXExtensions.CRLNumber_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    "sun.security.x509.CRLNumberExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        addInternal(CRL_REASON, PKIXExtensions.ReasonCode_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    "sun.security.x509.CRLReasonCodeExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        addInternal(NAME_CONSTRAINTS, PKIXExtensions.NameConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    "sun.security.x509.NameConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        addInternal(POLICY_MAPPINGS, PKIXExtensions.PolicyMappings_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    "sun.security.x509.PolicyMappingsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        addInternal(AUTH_KEY_IDENTIFIER, PKIXExtensions.AuthorityKey_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    "sun.security.x509.AuthorityKeyIdentifierExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        addInternal(POLICY_CONSTRAINTS, PKIXExtensions.PolicyConstraints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    "sun.security.x509.PolicyConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        addInternal(NETSCAPE_CERT, ObjectIdentifier.newInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    (new int[] {2,16,840,1,113730,1,1}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    "sun.security.x509.NetscapeCertTypeExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        addInternal(CERT_POLICIES, PKIXExtensions.CertificatePolicies_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    "sun.security.x509.CertificatePoliciesExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        addInternal(EXT_KEY_USAGE, PKIXExtensions.ExtendedKeyUsage_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    "sun.security.x509.ExtendedKeyUsageExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        addInternal(INHIBIT_ANY_POLICY, PKIXExtensions.InhibitAnyPolicy_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    "sun.security.x509.InhibitAnyPolicyExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        addInternal(CRL_DIST_POINTS, PKIXExtensions.CRLDistributionPoints_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    "sun.security.x509.CRLDistributionPointsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        addInternal(CERT_ISSUER, PKIXExtensions.CertificateIssuer_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    "sun.security.x509.CertificateIssuerExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        addInternal(AUTH_INFO_ACCESS, PKIXExtensions.AuthInfoAccess_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    "sun.security.x509.AuthorityInfoAccessExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        addInternal(ISSUING_DIST_POINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    PKIXExtensions.IssuingDistributionPoint_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    "sun.security.x509.IssuingDistributionPointExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        addInternal(DELTA_CRL_INDICATOR, PKIXExtensions.DeltaCRLIndicator_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    "sun.security.x509.DeltaCRLIndicatorExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        addInternal(FRESHEST_CRL, PKIXExtensions.FreshestCRL_Id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    "sun.security.x509.FreshestCRLExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Add attributes to the table. For internal use in the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static void addInternal(String name, ObjectIdentifier oid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        OIDInfo info = new OIDInfo(name, oid, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        oidMap.put(oid, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        nameMap.put(name, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Inner class encapsulating the mapping info and Class loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static class OIDInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        final ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        private volatile Class clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        OIDInfo(String name, ObjectIdentifier oid, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        OIDInfo(String name, ObjectIdentifier oid, Class clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            this.className = clazz.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            this.clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * Return the Class object associated with this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        Class getClazz() throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                Class c = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    c = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    clazz = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                throw (CertificateException)new CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                ("Could not load class: " + e).initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Add a name to lookup table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param name the name of the attr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param oid the string representation of the object identifier for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *         the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param clazz the Class object associated with this attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @exception CertificateException on errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static void addAttribute(String name, String oid, Class clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        ObjectIdentifier objId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            objId = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            throw new CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                ("Invalid Object identifier: " + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        OIDInfo info = new OIDInfo(name, objId, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (oidMap.put(objId, info) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw new CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                ("Object identifier already exists: " + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (nameMap.put(name, info) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new CertificateException("Name already exists: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Return user friendly name associated with the OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param oid the name of the object identifier to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return the user friendly name or null if no name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * is registered for this oid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public static String getName(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        OIDInfo info = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return (info == null) ? null : info.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return Object identifier for user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param name the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the Object Identifier or null if no oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * is registered for this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public static ObjectIdentifier getOID(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        OIDInfo info = nameMap.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return (info == null) ? null : info.oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Return the java class object associated with the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param name the user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @exception CertificateException if class cannot be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public static Class getClass(String name) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        OIDInfo info = nameMap.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return (info == null) ? null : info.getClazz();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Return the java class object associated with the object identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param oid the name of the object identifier to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @exception CertificateException if class cannot be instatiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public static Class getClass(ObjectIdentifier oid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        OIDInfo info = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return (info == null) ? null : info.getClazz();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}