jdk/src/share/classes/sun/security/x509/BasicConstraintsExtension.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2066 4230d224f27b
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-2006 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.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class represents the Basic Constraints Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>The basic constraints extension identifies whether the subject of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * certificate is a CA and how deep a certification path may exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * through that CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The ASN.1 syntax for this extension is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * BasicConstraints ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *     cA                BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *     pathLenConstraint INTEGER (0..MAX) OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see CertAttrSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class BasicConstraintsExtension extends Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
implements CertAttrSet<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Identifier for this attribute, to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * get, set, delete methods of Certificate, x509 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static final String IDENT = "x509.info.extensions.BasicConstraints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Attribute names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final String NAME = "BasicConstraints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final String IS_CA = "is_ca";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static final String PATH_LEN = "path_len";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Private data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean     ca = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int pathLen = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Encode this extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private void encodeThis() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (ca == false && pathLen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            this.extensionValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            tmp.putBoolean(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (pathLen >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            tmp.putInteger(pathLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.extensionValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Default constructor for this object. The extension is marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * critical if the ca flag is true, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param ca true, if the subject of the Certificate is a CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param len specifies the depth of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public BasicConstraintsExtension(boolean ca, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this(Boolean.valueOf(ca), ca, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Constructor for this object with specified criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param critical true, if the extension should be marked critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param ca true, if the subject of the Certificate is a CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param len specifies the depth of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public BasicConstraintsExtension(Boolean critical, boolean ca, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.ca = ca;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.pathLen = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Create the extension from the passed DER encoded value of the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param critical flag indicating if extension is critical or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param value an array containing the DER encoded bytes of the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @exception ClassCastException if value is not an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     public BasicConstraintsExtension(Boolean critical, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         this.extensionValue = (byte[]) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         DerValue val = new DerValue(this.extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
             throw new IOException("Invalid encoding of BasicConstraints");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         if (val.data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
             // non-CA cert ("cA" field is FALSE by default), return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         DerValue opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         if (opt.tag != DerValue.tag_Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
             // non-CA cert ("cA" field is FALSE by default), return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         this.ca = opt.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         if (val.data.available() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             // From PKIX profile:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
             // Where pathLenConstraint does not appear, there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
             // limit to the allowed length of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             this.pathLen = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         if (opt.tag != DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
             throw new IOException("Invalid encoding of BasicConstraints");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         this.pathLen = opt.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
          * Activate this check once again after PKIX profiling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
          * is a standard and this check no longer imposes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          * interoperability barrier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          * if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          *   if (!this.critical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
          *   throw new IOException("Criticality cannot be false for CA.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
          *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
          * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
          */
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
      * Return user readable form of extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         String s = super.toString() + "BasicConstraints:[\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         s += ((ca) ? ("  CA:true") : ("  CA:false")) + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         if (pathLen >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             s += "  PathLen:" + pathLen + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             s += "  PathLen: undefined\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         return (s + "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * Encode this extension value to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * @param out the DerOutputStream to encode the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         if (extensionValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                 critical = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                 critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         super.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (!(obj instanceof Boolean)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
              throw new IOException("Attribute value should be of type Boolean.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            ca = ((Boolean)obj).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (!(obj instanceof Integer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
              throw new IOException("Attribute value should be of type Integer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            pathLen = ((Integer)obj).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        encodeThis();
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
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public Object get(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return (Boolean.valueOf(ca));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return (Integer.valueOf(pathLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            ca = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            pathLen = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        elements.addElement(IS_CA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        elements.addElement(PATH_LEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return (elements.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return (NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
}