src/java.base/share/classes/sun/security/x509/PolicyConstraintsExtension.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
/*
28420
8fe17d073b54 8059916: Change default criticality of policy mappings and policy constraints certificate extensions
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package 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 defines the certificate extension which specifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Policy constraints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The policy constraints extension can be used in certificates issued
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to CAs. The policy constraints extension constrains path validation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * in two ways. It can be used to prohibit policy mapping or require
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * that each certificate in a path contain an acceptable policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * identifier.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The ASN.1 syntax for this is (IMPLICIT tagging is defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * module definition):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * PolicyConstraints ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     requireExplicitPolicy [0] SkipCerts OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     inhibitPolicyMapping  [1] SkipCerts OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * SkipCerts ::= INTEGER (0..MAX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see CertAttrSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class PolicyConstraintsExtension extends Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
implements CertAttrSet<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Identifier for this attribute, to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * get, set, delete methods of Certificate, x509 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final String IDENT = "x509.info.extensions.PolicyConstraints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Attribute names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final String NAME = "PolicyConstraints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final String REQUIRE = "require";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final String INHIBIT = "inhibit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final byte TAG_REQUIRE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final byte TAG_INHIBIT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private int require = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int inhibit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Encode this extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private void encodeThis() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (require == -1 && inhibit == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            this.extensionValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        DerOutputStream tagged = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (require != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            tmp.putInteger(require);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                         false, TAG_REQUIRE), tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (inhibit != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            tmp.putInteger(inhibit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                         false, TAG_INHIBIT), tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        seq.write(DerValue.tag_Sequence, tagged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.extensionValue = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Create a PolicyConstraintsExtension object with both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * require explicit policy and inhibit policy mapping. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * extension is marked non-critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param require require explicit policy (-1 for optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param inhibit inhibit policy mapping (-1 for optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public PolicyConstraintsExtension(int require, int inhibit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    throws IOException {
28420
8fe17d073b54 8059916: Change default criticality of policy mappings and policy constraints certificate extensions
juh
parents: 25859
diff changeset
   112
        this(Boolean.TRUE, require, inhibit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Create a PolicyConstraintsExtension object with specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * criticality and both require explicit policy and inhibit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * policy mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param critical true if the extension is to be treated as critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param require require explicit policy (-1 for optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param inhibit inhibit policy mapping (-1 for optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public PolicyConstraintsExtension(Boolean critical, int require, int inhibit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.require = require;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.inhibit = inhibit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.extensionId = PKIXExtensions.PolicyConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Create the extension from its DER encoded value and criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param critical true if the extension is to be treated as critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param value an array of DER encoded bytes of the actual value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @exception ClassCastException if value is not an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public PolicyConstraintsExtension(Boolean critical, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.extensionId = PKIXExtensions.PolicyConstraints_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        this.extensionValue = (byte[]) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        DerValue val = new DerValue(this.extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throw new IOException("Sequence tag missing for PolicyConstraint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        DerInputStream in = val.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        while (in != null && in.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            DerValue next = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (next.isContextSpecific(TAG_REQUIRE) && !next.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                if (this.require != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    throw new IOException("Duplicate requireExplicitPolicy" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                          "found in the PolicyConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                next.resetTag(DerValue.tag_Integer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                this.require = next.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            } else if (next.isContextSpecific(TAG_INHIBIT) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                       !next.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                if (this.inhibit != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    throw new IOException("Duplicate inhibitPolicyMapping" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                          "found in the PolicyConstraintsExtension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                next.resetTag(DerValue.tag_Integer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                this.inhibit = next.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                throw new IOException("Invalid encoding of PolicyConstraint");
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Return the extension as user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public String toString() {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   178
        StringBuilder sb = new StringBuilder();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   179
        sb.append(super.toString())
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   180
            .append("PolicyConstraints: [")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   181
            .append("  Require: ");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   182
        if (require == -1) {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   183
            sb.append("unspecified;");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   184
        } else {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   185
            sb.append(require)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   186
                .append(';');
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   187
        }
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   188
        sb.append("\tInhibit: ");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   189
        if (inhibit == -1) {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   190
            sb.append("unspecified");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   191
        } else {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   192
            sb.append(inhibit);
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   193
        }
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   194
        sb.append(" ]\n");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 28420
diff changeset
   195
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Write the extension to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (extensionValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
          extensionId = PKIXExtensions.PolicyConstraints_Id;
28420
8fe17d073b54 8059916: Change default criticality of policy mappings and policy constraints certificate extensions
juh
parents: 25859
diff changeset
   208
          critical = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
          encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        super.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public void set(String name, Object obj) throws IOException {
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
        if (name.equalsIgnoreCase(REQUIRE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            require = ((Integer)obj).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } else if (name.equalsIgnoreCase(INHIBIT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            inhibit = ((Integer)obj).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
          throw new IOException("Attribute name " + "[" + name + "]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                " not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                "CertAttrSet:PolicyConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   237
    public Integer get(String name) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (name.equalsIgnoreCase(REQUIRE)) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 10336
diff changeset
   239
            return require;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else if (name.equalsIgnoreCase(INHIBIT)) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 10336
diff changeset
   241
            return inhibit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                "CertAttrSet:PolicyConstraints.");
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
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (name.equalsIgnoreCase(REQUIRE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            require = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } else if (name.equalsIgnoreCase(INHIBIT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            inhibit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                "CertAttrSet:PolicyConstraints.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        elements.addElement(REQUIRE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        elements.addElement(INHIBIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return (elements.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return (NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}