src/java.base/share/classes/sun/security/x509/BasicConstraintsExtension.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 47216 71c04702a3d5
permissions -rw-r--r--
8200381: Typos in javadoc - missing verb "be" and alike Reviewed-by: lancea, darcy, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2066
diff changeset
     2
 * Copyright (c) 1997, 2009, 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: 2066
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: 2066
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: 2066
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2066
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2066
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.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
        DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            tmp.putBoolean(ca);
2066
4230d224f27b 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
weijun
parents: 2
diff changeset
    78
            // Only encode pathLen when ca == true
4230d224f27b 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
weijun
parents: 2
diff changeset
    79
            if (pathLen >= 0) {
4230d224f27b 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
weijun
parents: 2
diff changeset
    80
                tmp.putInteger(pathLen);
4230d224f27b 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
weijun
parents: 2
diff changeset
    81
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.extensionValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Default constructor for this object. The extension is marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * critical if the ca flag is true, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param ca true, if the subject of the Certificate is a CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param len specifies the depth of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public BasicConstraintsExtension(boolean ca, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this(Boolean.valueOf(ca), ca, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Constructor for this object with specified criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param critical true, if the extension should be marked critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param ca true, if the subject of the Certificate is a CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param len specifies the depth of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public BasicConstraintsExtension(Boolean critical, boolean ca, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.ca = ca;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.pathLen = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Create the extension from the passed DER encoded value of the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param critical flag indicating if extension is critical or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param value an array containing the DER encoded bytes of the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @exception ClassCastException if value is not an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     public BasicConstraintsExtension(Boolean critical, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         this.extensionValue = (byte[]) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         DerValue val = new DerValue(this.extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
             throw new IOException("Invalid encoding of BasicConstraints");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
2066
4230d224f27b 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
weijun
parents: 2
diff changeset
   134
         if (val.data == null || val.data.available() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
             // non-CA cert ("cA" field is FALSE by default), return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         DerValue opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         if (opt.tag != DerValue.tag_Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
             // non-CA cert ("cA" field is FALSE by default), return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         this.ca = opt.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         if (val.data.available() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
             // From PKIX profile:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
             // Where pathLenConstraint does not appear, there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             // limit to the allowed length of the certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             this.pathLen = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         if (opt.tag != DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
             throw new IOException("Invalid encoding of BasicConstraints");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         this.pathLen = opt.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
          * Activate this check once again after PKIX profiling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
          * is a standard and this check no longer imposes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
          * interoperability barrier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
          * if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
          *   if (!this.critical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          *   throw new IOException("Criticality cannot be false for CA.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          * }
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
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      * Return user readable form of extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     public String toString() {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   174
         return super.toString() +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   175
             "BasicConstraints:[\n  CA:" + ca +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   176
             "\n  PathLen:" +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   177
             ((pathLen >= 0) ? String.valueOf(pathLen) : " undefined") +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   178
             "\n]\n";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      * Encode this extension value to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      * @param out the DerOutputStream to encode the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         if (extensionValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             this.extensionId = PKIXExtensions.BasicConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             if (ca) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                 critical = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                 critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
             encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         super.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (!(obj instanceof Boolean)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
              throw new IOException("Attribute value should be of type Boolean.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            ca = ((Boolean)obj).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (!(obj instanceof Integer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
              throw new IOException("Attribute value should be of type Integer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            pathLen = ((Integer)obj).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public Object get(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return (Boolean.valueOf(ca));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return (Integer.valueOf(pathLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (name.equalsIgnoreCase(IS_CA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            ca = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } else if (name.equalsIgnoreCase(PATH_LEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            pathLen = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                "CertAttrSet:BasicConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        elements.addElement(IS_CA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        elements.addElement(PATH_LEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return (elements.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return (NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}