001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.security.x509;
022:
023: import java.io.IOException;
024: import javax.security.auth.x500.X500Principal;
025:
026: import org.apache.harmony.security.asn1.ASN1Choice;
027: import org.apache.harmony.security.asn1.ASN1Implicit;
028: import org.apache.harmony.security.asn1.ASN1Type;
029: import org.apache.harmony.security.asn1.BerInputStream;
030: import org.apache.harmony.security.x501.Name;
031:
032: /**
033: * The class encapsulates the ASN.1 DER encoding/decoding work
034: * with the DistributionPointName structure which is the part
035: * of X.509 CRL
036: * (as specified in RFC 3280 -
037: * Internet X.509 Public Key Infrastructure.
038: * Certificate and Certificate Revocation List (CRL) Profile.
039: * http://www.ietf.org/rfc/rfc3280.txt):
040: *
041: * <pre>
042: * CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
043: *
044: * DistributionPoint ::= SEQUENCE {
045: * distributionPoint [0] DistributionPointName OPTIONAL,
046: * reasons [1] ReasonFlags OPTIONAL,
047: * cRLIssuer [2] GeneralNames OPTIONAL
048: * }
049: *
050: * DistributionPointName ::= CHOICE {
051: * fullName [0] GeneralNames,
052: * nameRelativeToCRLIssuer [1] RelativeDistinguishedName
053: * }
054: *
055: * ReasonFlags ::= BIT STRING {
056: * unused (0),
057: * keyCompromise (1),
058: * cACompromise (2),
059: * affiliationChanged (3),
060: * superseded (4),
061: * cessationOfOperation (5),
062: * certificateHold (6),
063: * privilegeWithdrawn (7),
064: * aACompromise (8)
065: * }
066: * </pre>
067: */
068: public class DistributionPointName {
069:
070: private final GeneralNames fullName;
071: private final Name nameRelativeToCRLIssuer;
072:
073: public DistributionPointName(GeneralNames fullName) {
074: this .fullName = fullName;
075: this .nameRelativeToCRLIssuer = null;
076: }
077:
078: public DistributionPointName(Name nameRelativeToCRLIssuer) {
079: this .fullName = null;
080: this .nameRelativeToCRLIssuer = nameRelativeToCRLIssuer;
081: }
082:
083: /**
084: * Places the string representation of extension value
085: * into the StringBuffer object.
086: */
087: public void dumpValue(StringBuffer buffer, String prefix) {
088: buffer.append(prefix);
089: buffer.append("Distribution Point Name: [\n"); //$NON-NLS-1$
090: if (fullName != null) {
091: fullName.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
092: } else {
093: buffer.append(prefix);
094: buffer.append(" "); //$NON-NLS-1$
095: buffer.append(nameRelativeToCRLIssuer
096: .getName(X500Principal.RFC2253));
097: }
098: buffer.append(prefix);
099: buffer.append("]\n"); //$NON-NLS-1$
100: }
101:
102: public static final ASN1Choice ASN1 = new ASN1Choice(
103: new ASN1Type[] { new ASN1Implicit(0, GeneralNames.ASN1),
104: new ASN1Implicit(1, Name.ASN1_RDN) }) {
105:
106: public int getIndex(java.lang.Object object) {
107: DistributionPointName dpn = (DistributionPointName) object;
108: return (dpn.fullName == null) ? 1 : 0;
109: }
110:
111: protected Object getDecodedObject(BerInputStream in)
112: throws IOException {
113: DistributionPointName result = null;
114: if (in.choiceIndex == 0) {
115: result = new DistributionPointName(
116: (GeneralNames) in.content);
117: } else {
118: // note: ASN.1 decoder will report an error if index
119: // is neither 0 or 1
120: result = new DistributionPointName((Name) in.content);
121: }
122: return result;
123: }
124:
125: public Object getObjectToEncode(Object object) {
126: DistributionPointName dpn = (DistributionPointName) object;
127: if (dpn.fullName == null) {
128: return dpn.nameRelativeToCRLIssuer;
129: } else {
130: return dpn.fullName;
131: }
132: }
133: };
134: }
|