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