jdk/src/java.base/share/classes/sun/security/x509/CRLDistributionPointsExtension.java
author igerasim
Mon, 18 May 2015 17:38:38 +0300
changeset 30649 e7cc8f48f616
parent 30374 2abaf49910ea
child 35283 c5082624b79f
permissions -rw-r--r--
8080522: Optimize string operations in java.base/share/classes/sun/security/x509/ Reviewed-by: mullan
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) 2002, 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.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.DerOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.DerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.ObjectIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Represent the CRL Distribution Points Extension (OID = 2.5.29.31).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The CRL distribution points extension identifies how CRL information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is obtained.  The extension SHOULD be non-critical, but the PKIX profile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * recommends support for this extension by CAs and applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * For PKIX, if the cRLDistributionPoints extension contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * DistributionPointName of type URI, the following semantics MUST be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * assumed: the URI is a pointer to the current CRL for the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * reasons and will be issued by the associated cRLIssuer.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * expected values for the URI conform to the following rules.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * name MUST be a non-relative URL, and MUST follow the URL syntax and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * encoding rules specified in [RFC 1738].  The name must include both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a scheme (e.g., "http" or "ftp") and a scheme-specific-part.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * scheme- specific-part must include a fully qualified domain name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * IP address as the host.  As specified in [RFC 1738], the scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * name is not case-sensitive (e.g., "http" is equivalent to "HTTP").
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The host part is also not case-sensitive, but other components of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the scheme-specific-part may be case-sensitive. When comparing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * URIs, conforming implementations MUST compare the scheme and host
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * without regard to case, but assume the remainder of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * scheme-specific-part is case sensitive.  Processing rules for other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * values are not defined by this specification.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * distributionPoint omits reasons, the CRL MUST include revocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * for all reasons. If the distributionPoint omits cRLIssuer, the CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * MUST be issued by the CA that issued the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::=  { id-ce 31 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * cRLDistributionPoints ::= {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *      CRLDistPointsSyntax }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * CRLDistPointsSyntax ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * </pre>
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
    74
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author Anne Anderson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @since 1.4.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see DistributionPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see CertAttrSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public class CRLDistributionPointsExtension extends Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        implements CertAttrSet<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Identifier for this attribute, to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * get, set, delete methods of Certificate, x509 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final String IDENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                "x509.info.extensions.CRLDistributionPoints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final String NAME = "CRLDistributionPoints";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static final String POINTS = "points";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * The List of DistributionPoint objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private List<DistributionPoint> distributionPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String extensionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Create a CRLDistributionPointsExtension from a List of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * DistributionPoint; the criticality is set to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param distributionPoints the list of distribution points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public CRLDistributionPointsExtension(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        List<DistributionPoint> distributionPoints) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this(false, distributionPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Create a CRLDistributionPointsExtension from a List of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * DistributionPoint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param isCritical the criticality setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param distributionPoints the list of distribution points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public CRLDistributionPointsExtension(boolean isCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        List<DistributionPoint> distributionPoints) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this(PKIXExtensions.CRLDistributionPoints_Id, isCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            distributionPoints, NAME);
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
     * Creates the extension (also called by the subclass).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected CRLDistributionPointsExtension(ObjectIdentifier extensionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        boolean isCritical, List<DistributionPoint> distributionPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            String extensionName) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this.extensionId = extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.critical = isCritical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.distributionPoints = distributionPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.extensionName = extensionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Create the extension from the passed DER encoded value of the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param critical true if the extension is to be treated as critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param value Array of DER encoded bytes of the actual value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public CRLDistributionPointsExtension(Boolean critical, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this(PKIXExtensions.CRLDistributionPoints_Id, critical, value, NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Creates the extension (also called by the subclass).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected CRLDistributionPointsExtension(ObjectIdentifier extensionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Boolean critical, Object value, String extensionName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.extensionId = extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (!(value instanceof byte[])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new IOException("Illegal argument type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        extensionValue = (byte[])value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        DerValue val = new DerValue(extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new IOException("Invalid encoding for " + extensionName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                  " extension.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        distributionPoints = new ArrayList<DistributionPoint>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        while (val.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            DerValue seq = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            DistributionPoint point = new DistributionPoint(seq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            distributionPoints.add(point);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        this.extensionName = extensionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return extensionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Write the extension to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        encode(out, PKIXExtensions.CRLDistributionPoints_Id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Write the extension to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * (Also called by the subclass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected void encode(OutputStream out, ObjectIdentifier extensionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        boolean isCritical) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (this.extensionValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            this.extensionId = extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            this.critical = isCritical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        out.write(tmp.toByteArray());
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
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   225
    @SuppressWarnings("unchecked") // Checked with instanceof
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (name.equalsIgnoreCase(POINTS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (!(obj instanceof List)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                throw new IOException("Attribute value should be of type List.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            distributionPoints = (List<DistributionPoint>)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw new IOException("Attribute name [" + name +
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   234
                                  "] not recognized by " +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   235
                                  "CertAttrSet:" + extensionName + '.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   243
    public List<DistributionPoint> get(String name) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (name.equalsIgnoreCase(POINTS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return distributionPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new IOException("Attribute name [" + name +
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   248
                                  "] not recognized by " +
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   249
                                  "CertAttrSet:" + extensionName + '.');
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (name.equalsIgnoreCase(POINTS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            distributionPoints = new ArrayList<DistributionPoint>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            throw new IOException("Attribute name [" + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                "] not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                "CertAttrSet:" + extensionName + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        elements.addElement(POINTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     // Encode this extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private void encodeThis() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (distributionPoints.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            this.extensionValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            DerOutputStream pnts = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            for (DistributionPoint point : distributionPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                point.encode(pnts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            seq.write(DerValue.tag_Sequence, pnts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            this.extensionValue = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Return the extension as user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return super.toString() + extensionName + " [\n  "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
               + distributionPoints + "]\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}