001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.cmp;
021:
022: import java.util.Enumeration;
023: import java.util.Vector;
024:
025: import org.bouncycastle.asn1.ASN1EncodableVector;
026: import org.bouncycastle.asn1.ASN1Sequence;
027: import org.bouncycastle.asn1.ASN1TaggedObject;
028: import org.bouncycastle.asn1.DEREncodable;
029: import org.bouncycastle.asn1.DERObject;
030: import org.bouncycastle.asn1.DERSequence;
031: import org.bouncycastle.asn1.x509.CertificateList;
032:
033: /**
034: * ASN.1 structure DER En/DeCoder.
035: *
036: * <pre>
037: * CRLAnnContent ::= SEQUENCE OF CertificateList
038: *
039: * </pre>
040: */
041: public class CRLAnnContent implements DEREncodable {
042: Vector certificateLists = new Vector();
043:
044: public static CRLAnnContent getInstance(ASN1TaggedObject obj,
045: boolean explicit) {
046: return getInstance(ASN1Sequence.getInstance(obj, explicit));
047: }
048:
049: public static CRLAnnContent getInstance(Object obj) {
050: if (obj instanceof CRLAnnContent) {
051: return (CRLAnnContent) obj;
052: } else if (obj instanceof ASN1Sequence) {
053: return new CRLAnnContent((ASN1Sequence) obj);
054: }
055:
056: throw new IllegalArgumentException("unknown object in factory");
057: }
058:
059: public CRLAnnContent(ASN1Sequence seq) {
060: Enumeration e = seq.getObjects();
061: while (e.hasMoreElements()) {
062: CertificateList s = CertificateList.getInstance(e
063: .nextElement());
064: certificateLists.addElement(s);
065: }
066: }
067:
068: public CRLAnnContent(CertificateList certificateList) {
069: certificateLists.addElement(certificateList);
070: }
071:
072: public void addCertificateList(CertificateList certificateList) {
073: certificateLists.addElement(certificateList);
074: }
075:
076: public CertificateList getCertificateList(int nr) {
077: if (certificateLists.size() > nr)
078: return (CertificateList) certificateLists.elementAt(nr);
079:
080: return null;
081: }
082:
083: public DERObject getDERObject() {
084: ASN1EncodableVector v = new ASN1EncodableVector();
085:
086: for (int i = 0; i < certificateLists.size(); i++) {
087: v.add((CertificateList) certificateLists.elementAt(i));
088: }
089:
090: return new DERSequence(v);
091: }
092:
093: public String toString() {
094: String p = null;
095: for (int i = 0; i < certificateLists.size(); i++) {
096: if (p == null)
097: p = ((CertificateList) certificateLists.elementAt(i))
098: .toString();
099: else
100: p += (CertificateList) certificateLists.elementAt(i);
101: }
102: return "CRLAnnContent: " + p;
103: }
104: }
|