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:
025: import org.apache.harmony.security.asn1.ASN1Explicit;
026: import org.apache.harmony.security.asn1.ASN1Implicit;
027: import org.apache.harmony.security.asn1.ASN1Sequence;
028: import org.apache.harmony.security.asn1.ASN1Type;
029: import org.apache.harmony.security.asn1.BerInputStream;
030: import org.apache.harmony.security.internal.nls.Messages;
031:
032: /**
033: * The class encapsulates the ASN.1 DER encoding/decoding work
034: * with the DistributionPoint structure which is the part of X.509 CRL
035: * (as specified in RFC 3280 -
036: * Internet X.509 Public Key Infrastructure.
037: * Certificate and Certificate Revocation List (CRL) Profile.
038: * http://www.ietf.org/rfc/rfc3280.txt):
039: *
040: * <pre>
041: * CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
042: *
043: * DistributionPoint ::= SEQUENCE {
044: * distributionPoint [0] DistributionPointName OPTIONAL,
045: * reasons [1] ReasonFlags OPTIONAL,
046: * cRLIssuer [2] GeneralNames OPTIONAL
047: * }
048: *
049: * DistributionPointName ::= CHOICE {
050: * fullName [0] GeneralNames,
051: * nameRelativeToCRLIssuer [1] RelativeDistinguishedName
052: * }
053: *
054: * ReasonFlags ::= BIT STRING {
055: * unused (0),
056: * keyCompromise (1),
057: * cACompromise (2),
058: * affiliationChanged (3),
059: * superseded (4),
060: * cessationOfOperation (5),
061: * certificateHold (6),
062: * privilegeWithdrawn (7),
063: * aACompromise (8)
064: * }
065: * </pre>
066: */
067: public class DistributionPoint {
068:
069: private final DistributionPointName distributionPoint;
070: private final ReasonFlags reasons;
071: private final GeneralNames cRLIssuer;
072:
073: public DistributionPoint() {
074: distributionPoint = null;
075: reasons = null;
076: cRLIssuer = null;
077: }
078:
079: public DistributionPoint(DistributionPointName distributionPoint,
080: ReasonFlags reasons, GeneralNames cRLIssuer) {
081: if ((reasons != null) && (distributionPoint == null)
082: && (cRLIssuer == null)) {
083: throw new IllegalArgumentException(Messages
084: .getString("security.17F")); //$NON-NLS-1$
085: }
086: this .distributionPoint = distributionPoint;
087: this .reasons = reasons;
088: this .cRLIssuer = cRLIssuer;
089: }
090:
091: /**
092: * Places the string representation of extension value
093: * into the StringBuffer object.
094: */
095: public void dumpValue(StringBuffer buffer, String prefix) {
096: buffer.append(prefix);
097: buffer.append("Distribution Point: [\n"); //$NON-NLS-1$
098: if (distributionPoint != null) {
099: distributionPoint.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
100: }
101: if (reasons != null) {
102: reasons.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
103: }
104: if (cRLIssuer != null) {
105: buffer.append(prefix);
106: buffer.append(" CRL Issuer: [\n"); //$NON-NLS-1$
107: cRLIssuer.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
108: buffer.append(prefix);
109: buffer.append(" ]\n"); //$NON-NLS-1$
110: }
111: buffer.append(prefix);
112: buffer.append("]\n"); //$NON-NLS-1$
113: }
114:
115: /**
116: * Custom X.509 decoder.
117: */
118: public static final ASN1Sequence ASN1 = new ASN1Sequence(
119: new ASN1Type[] {
120: new ASN1Explicit(0, DistributionPointName.ASN1),
121: new ASN1Implicit(1, ReasonFlags.ASN1),
122: new ASN1Implicit(2, GeneralNames.ASN1) }) {
123: {
124: setOptional(0);
125: setOptional(1);
126: setOptional(2);
127: }
128:
129: protected Object getDecodedObject(BerInputStream in)
130: throws IOException {
131: Object[] values = (Object[]) in.content;
132: return new DistributionPoint(
133: (DistributionPointName) values[0],
134: (ReasonFlags) values[1], (GeneralNames) values[2]);
135: }
136:
137: protected void getValues(Object object, Object[] values) {
138: DistributionPoint dp = (DistributionPoint) object;
139: values[0] = dp.distributionPoint;
140: values[1] = dp.reasons;
141: values[2] = dp.cRLIssuer;
142: }
143: };
144: }
|