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 java.util.Iterator;
025: import java.util.Collection;
026: import java.util.List;
027:
028: import org.apache.harmony.security.asn1.ASN1SequenceOf;
029: import org.apache.harmony.security.asn1.ASN1Type;
030: import org.apache.harmony.security.asn1.BerInputStream;
031: import org.apache.harmony.security.internal.nls.Messages;
032:
033: /**
034: * The class encapsulates the ASN.1 DER encoding/decoding work
035: * with the CRL Distribution Points which is the part of X.509 Certificate
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 CRLDistributionPoints extends ExtensionValue {
069:
070: private List distributionPoints;
071: private byte[] encoding;
072:
073: public CRLDistributionPoints(List distributionPoints) {
074: if ((distributionPoints == null)
075: || (distributionPoints.size() == 0)) {
076: throw new IllegalArgumentException(Messages
077: .getString("security.17D")); //$NON-NLS-1$
078: }
079: this .distributionPoints = distributionPoints;
080: }
081:
082: public CRLDistributionPoints(List distributionPoints,
083: byte[] encoding) {
084: if ((distributionPoints == null)
085: || (distributionPoints.size() == 0)) {
086: throw new IllegalArgumentException(Messages
087: .getString("security.17D")); //$NON-NLS-1$
088: }
089: this .distributionPoints = distributionPoints;
090: this .encoding = encoding;
091: }
092:
093: public byte[] getEncoded() {
094: if (encoding == null) {
095: encoding = ASN1.encode(this );
096: }
097: return encoding;
098: }
099:
100: public static CRLDistributionPoints decode(byte[] encoding)
101: throws IOException {
102: CRLDistributionPoints cdp = (CRLDistributionPoints) ASN1
103: .decode(encoding);
104: return cdp;
105: }
106:
107: /**
108: * Places the string representation of extension value
109: * into the StringBuffer object.
110: */
111: public void dumpValue(StringBuffer buffer, String prefix) {
112: buffer.append(prefix).append("CRL Distribution Points: [\n"); //$NON-NLS-1$
113: int number = 0;
114: for (Iterator it = distributionPoints.iterator(); it.hasNext();) {
115: buffer.append(prefix)
116: .append(" [").append(++number).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
117: ((DistributionPoint) it.next()).dumpValue(buffer, prefix
118: + " "); //$NON-NLS-1$
119: }
120: buffer.append(prefix).append("]\n"); //$NON-NLS-1$
121: }
122:
123: /**
124: * Custom X.509 decoder.
125: */
126: public static final ASN1Type ASN1 = new ASN1SequenceOf(
127: DistributionPoint.ASN1) {
128:
129: public Object getDecodedObject(BerInputStream in) {
130: return new CRLDistributionPoints((List) in.content, in
131: .getEncoded());
132: }
133:
134: public Collection getValues(Object object) {
135: CRLDistributionPoints dps = (CRLDistributionPoints) object;
136: return dps.distributionPoints;
137: }
138: };
139: }
|