src/java.base/share/classes/sun/security/x509/PolicyInformation.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
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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.security.cert.PolicyQualifierInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.LinkedHashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.util.DerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.DerOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * PolicyInformation is the class that contains a specific certificate policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * that is part of the CertificatePoliciesExtension. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * CertificatePolicyExtension value consists of a vector of these objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The ASN.1 syntax for PolicyInformation (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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * PolicyInformation ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      policyIdentifier   CertPolicyId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      policyQualifiers   SEQUENCE SIZE (1..MAX) OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *                              PolicyQualifierInfo OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * CertPolicyId ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * PolicyQualifierInfo ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      policyQualifierId  PolicyQualifierId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      qualifier          ANY DEFINED BY policyQualifierId }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Anne Anderson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class PolicyInformation {
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
    public static final String NAME       = "PolicyInformation";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final String ID         = "id";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final String QUALIFIERS = "qualifiers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* The policy OID */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private CertificatePolicyId policyIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* A Set of java.security.cert.PolicyQualifierInfo objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private Set<PolicyQualifierInfo> policyQualifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Create an instance of PolicyInformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param policyIdentifier the policyIdentifier as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *          CertificatePolicyId
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param policyQualifiers a Set of PolicyQualifierInfo objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *          Must not be NULL. Specify an empty Set for no qualifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @exception IOException on decoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public PolicyInformation(CertificatePolicyId policyIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            Set<PolicyQualifierInfo> policyQualifiers) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (policyQualifiers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new NullPointerException("policyQualifiers is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.policyQualifiers =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            new LinkedHashSet<PolicyQualifierInfo>(policyQualifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.policyIdentifier = policyIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Create an instance of PolicyInformation, decoding from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * the passed DerValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param val the DerValue to construct the PolicyInformation from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @exception IOException on decoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public PolicyInformation(DerValue val) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new IOException("Invalid encoding of PolicyInformation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (val.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            DerValue opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (opt.tag != DerValue.tag_Sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                throw new IOException("Invalid encoding of PolicyInformation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (opt.data.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                throw new IOException("No data available in policyQualifiers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            while (opt.data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                policyQualifiers.add(new PolicyQualifierInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        (opt.data.getDerValue().toByteArray()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            policyQualifiers = Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Compare this PolicyInformation with another object for equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param other object to be compared with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return true iff the PolicyInformation objects match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (!(other instanceof PolicyInformation))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        PolicyInformation piOther = (PolicyInformation)other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!policyIdentifier.equals(piOther.getPolicyIdentifier()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return policyQualifiers.equals(piOther.getPolicyQualifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns the hash code for this PolicyInformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return a hash code value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int myhash = 37 + policyIdentifier.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        myhash = 37 * myhash + policyQualifiers.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return myhash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Return the policyIdentifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return The CertificatePolicyId object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *     the policyIdentifier (not a copy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public CertificatePolicyId getPolicyIdentifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return policyIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Return the policyQualifiers value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return a Set of PolicyQualifierInfo objects associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *    with this certificate policy (not a copy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *    Returns an empty Set if there are no qualifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *    Never returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public Set<PolicyQualifierInfo> getPolicyQualifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return policyQualifiers;
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
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public Object get(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (name.equalsIgnoreCase(ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return policyIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } else if (name.equalsIgnoreCase(QUALIFIERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return policyQualifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                "] not recognized by PolicyInformation.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   189
    @SuppressWarnings("unchecked") // Checked with instanceof
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (name.equalsIgnoreCase(ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (obj instanceof CertificatePolicyId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                policyIdentifier = (CertificatePolicyId)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                throw new IOException("Attribute value must be instance " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    "of CertificatePolicyId.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } else if (name.equalsIgnoreCase(QUALIFIERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (policyIdentifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                throw new IOException("Attribute must have a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    "CertificatePolicyIdentifier value before " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    "PolicyQualifierInfo can be set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (obj instanceof Set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                Iterator<?> i = ((Set<?>)obj).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    Object obj1 = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (!(obj1 instanceof PolicyQualifierInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        throw new IOException("Attribute value must be a" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                    "Set of PolicyQualifierInfo objects.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                policyQualifiers = (Set<PolicyQualifierInfo>) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new IOException("Attribute value must be of type Set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                "] not recognized by PolicyInformation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (name.equalsIgnoreCase(QUALIFIERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            policyQualifiers = Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else if (name.equalsIgnoreCase(ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            throw new IOException("Attribute ID may not be deleted from " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                "PolicyInformation.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            //ID may not be deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                "] not recognized by PolicyInformation.");
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        elements.addElement(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        elements.addElement(QUALIFIERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Return a printable representation of the PolicyInformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public String toString() {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   261
        return "  [" + policyIdentifier + policyQualifiers + "  ]\n";
2
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
     * Write the PolicyInformation to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        policyIdentifier.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (!policyQualifiers.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            DerOutputStream tmp2 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            for (PolicyQualifierInfo pq : policyQualifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                tmp2.write(pq.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            tmp.write(DerValue.tag_Sequence, tmp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}