0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.x509;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.util.*;
0N/A
0N/Aimport sun.security.util.BitArray;
0N/Aimport sun.security.util.DerOutputStream;
0N/Aimport sun.security.util.DerValue;
0N/A
0N/A/**
0N/A * Represents the DistributionPointName ASN.1 type.
0N/A *
0N/A * It is used in the CRL Distribution Points Extension (OID = 2.5.29.31)
0N/A * and the Issuing Distribution Point Extension (OID = 2.5.29.28).
0N/A * <p>
0N/A * Its ASN.1 definition is:
0N/A * <pre>
0N/A *
0N/A * DistributionPointName ::= CHOICE {
0N/A * fullName [0] GeneralNames,
0N/A * nameRelativeToCRLIssuer [1] RelativeDistinguishedName }
0N/A *
0N/A * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
0N/A *
0N/A * GeneralName ::= CHOICE {
0N/A * otherName [0] INSTANCE OF OTHER-NAME,
0N/A * rfc822Name [1] IA5String,
0N/A * dNSName [2] IA5String,
0N/A * x400Address [3] ORAddress,
0N/A * directoryName [4] Name,
0N/A * ediPartyName [5] EDIPartyName,
0N/A * uniformResourceIdentifier [6] IA5String,
0N/A * iPAddress [7] OCTET STRING,
0N/A * registeredID [8] OBJECT IDENTIFIER }
0N/A *
0N/A * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
0N/A *
0N/A * AttributeTypeAndValue ::= SEQUENCE {
0N/A * type AttributeType,
0N/A * value AttributeValue }
0N/A *
0N/A * AttributeType ::= OBJECT IDENTIFIER
0N/A *
0N/A * AttributeValue ::= ANY DEFINED BY AttributeType
0N/A *
0N/A * </pre>
0N/A * <p>
0N/A * Instances of this class are designed to be immutable. However, since this
0N/A * is an internal API we do not use defensive cloning for values for
0N/A * performance reasons. It is the responsibility of the consumer to ensure
0N/A * that no mutable elements are modified.
0N/A *
0N/A * @see CRLDistributionPointsExtension
0N/A * @see IssuingDistributionPointExtension
0N/A * @since 1.6
0N/A */
0N/Apublic class DistributionPointName {
0N/A
0N/A // ASN.1 context specific tag values
0N/A private static final byte TAG_FULL_NAME = 0;
0N/A private static final byte TAG_RELATIVE_NAME = 1;
0N/A
0N/A // Only one of fullName and relativeName can be set
0N/A private GeneralNames fullName = null;
0N/A private RDN relativeName = null;
0N/A
0N/A // Cached hashCode value
0N/A private volatile int hashCode;
0N/A
0N/A /**
0N/A * Creates a distribution point name using a full name.
0N/A *
0N/A * @param fullName the name for the distribution point.
0N/A * @exception IllegalArgumentException if <code>fullName</code> is null.
0N/A */
0N/A public DistributionPointName(GeneralNames fullName) {
0N/A
0N/A if (fullName == null) {
0N/A throw new IllegalArgumentException("fullName must not be null");
0N/A }
0N/A this.fullName = fullName;
0N/A }
0N/A
0N/A /**
0N/A * Creates a distribution point name using a relative name.
0N/A *
0N/A * @param relativeName the name of the distribution point relative to
0N/A * the name of the issuer of the CRL.
0N/A * @exception IllegalArgumentException if <code>relativeName</code> is null.
0N/A */
0N/A public DistributionPointName(RDN relativeName) {
0N/A
0N/A if (relativeName == null) {
0N/A throw new IllegalArgumentException("relativeName must not be null");
0N/A }
0N/A this.relativeName = relativeName;
0N/A }
0N/A
0N/A /**
0N/A * Creates a distribution point name from its DER-encoded form.
0N/A *
0N/A * @param encoding the DER-encoded value.
0N/A * @throws IOException on decoding error.
0N/A */
0N/A public DistributionPointName(DerValue encoding) throws IOException {
0N/A
0N/A if (encoding.isContextSpecific(TAG_FULL_NAME) &&
0N/A encoding.isConstructed()) {
0N/A
0N/A encoding.resetTag(DerValue.tag_Sequence);
0N/A fullName = new GeneralNames(encoding);
0N/A
0N/A } else if (encoding.isContextSpecific(TAG_RELATIVE_NAME) &&
0N/A encoding.isConstructed()) {
0N/A
0N/A encoding.resetTag(DerValue.tag_Set);
0N/A relativeName = new RDN(encoding);
0N/A
0N/A } else {
0N/A throw new IOException("Invalid encoding for DistributionPointName");
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Returns the full name for the distribution point or null if not set.
0N/A */
0N/A public GeneralNames getFullName() {
0N/A return fullName;
0N/A }
0N/A
0N/A /**
0N/A * Returns the relative name for the distribution point or null if not set.
0N/A */
0N/A public RDN getRelativeName() {
0N/A return relativeName;
0N/A }
0N/A
0N/A /**
0N/A * Encodes the distribution point name and writes it to the DerOutputStream.
0N/A *
0N/A * @param out the output stream.
0N/A * @exception IOException on encoding error.
0N/A */
0N/A public void encode(DerOutputStream out) throws IOException {
0N/A
0N/A DerOutputStream theChoice = new DerOutputStream();
0N/A
0N/A if (fullName != null) {
0N/A fullName.encode(theChoice);
0N/A out.writeImplicit(
0N/A DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FULL_NAME),
0N/A theChoice);
0N/A
0N/A } else {
0N/A relativeName.encode(theChoice);
0N/A out.writeImplicit(
0N/A DerValue.createTag(DerValue.TAG_CONTEXT, true,
0N/A TAG_RELATIVE_NAME),
0N/A theChoice);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Compare an object to this distribution point name for equality.
0N/A *
0N/A * @param obj Object to be compared to this
0N/A * @return true if objects match; false otherwise
0N/A */
0N/A public boolean equals(Object obj) {
0N/A if (this == obj) {
0N/A return true;
0N/A }
0N/A if (obj instanceof DistributionPointName == false) {
0N/A return false;
0N/A }
0N/A DistributionPointName other = (DistributionPointName)obj;
0N/A
0N/A return equals(this.fullName, other.fullName) &&
0N/A equals(this.relativeName, other.relativeName);
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code for this distribution point name.
0N/A *
0N/A * @return the hash code.
0N/A */
0N/A public int hashCode() {
0N/A int hash = hashCode;
0N/A if (hash == 0) {
0N/A hash = 1;
0N/A if (fullName != null) {
0N/A hash += fullName.hashCode();
0N/A
0N/A } else {
0N/A hash += relativeName.hashCode();
0N/A }
0N/A hashCode = hash;
0N/A }
0N/A return hash;
0N/A }
0N/A
0N/A /**
0N/A * Returns a printable string of the distribution point name.
0N/A */
0N/A public String toString() {
0N/A StringBuilder sb = new StringBuilder();
0N/A if (fullName != null) {
0N/A sb.append("DistributionPointName:\n " + fullName + "\n");
0N/A
0N/A } else {
0N/A sb.append("DistributionPointName:\n " + relativeName + "\n");
0N/A }
0N/A
0N/A return sb.toString();
0N/A }
0N/A
0N/A /*
0N/A * Utility function for a.equals(b) where both a and b may be null.
0N/A */
0N/A private static boolean equals(Object a, Object b) {
0N/A return (a == null) ? (b == null) : a.equals(b);
0N/A }
0N/A}