jdk/src/share/classes/sun/security/x509/PolicyInformation.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
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 2000-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.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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (name.equalsIgnoreCase(ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (obj instanceof CertificatePolicyId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                policyIdentifier = (CertificatePolicyId)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                throw new IOException("Attribute value must be instance " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    "of CertificatePolicyId.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else if (name.equalsIgnoreCase(QUALIFIERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (policyIdentifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                throw new IOException("Attribute must have a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    "CertificatePolicyIdentifier value before " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    "PolicyQualifierInfo can be set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (obj instanceof Set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                Iterator<?> i = ((Set<?>)obj).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    Object obj1 = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    if (!(obj1 instanceof PolicyQualifierInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        throw new IOException("Attribute value must be a" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                    "Set of PolicyQualifierInfo objects.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                policyQualifiers = (Set<PolicyQualifierInfo>) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                throw new IOException("Attribute value must be of type Set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                "] not recognized by PolicyInformation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
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
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (name.equalsIgnoreCase(QUALIFIERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            policyQualifiers = Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } else if (name.equalsIgnoreCase(ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new IOException("Attribute ID may not be deleted from " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                "PolicyInformation.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            //ID may not be deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                "] not recognized by PolicyInformation.");
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
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        elements.addElement(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        elements.addElement(QUALIFIERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Return a printable representation of the PolicyInformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        StringBuilder s = new StringBuilder("  [" + policyIdentifier.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        s.append(policyQualifiers + "  ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return s.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Write the PolicyInformation to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        policyIdentifier.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (!policyQualifiers.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            DerOutputStream tmp2 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            for (PolicyQualifierInfo pq : policyQualifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                tmp2.write(pq.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            tmp.write(DerValue.tag_Sequence, tmp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}