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.crmf;
021:
022: import java.util.Vector;
023:
024: import org.bouncycastle.asn1.ASN1EncodableVector;
025: import org.bouncycastle.asn1.ASN1Sequence;
026: import org.bouncycastle.asn1.ASN1TaggedObject;
027: import org.bouncycastle.asn1.DEREncodable;
028: import org.bouncycastle.asn1.DERInteger;
029: import org.bouncycastle.asn1.DERObject;
030: import org.bouncycastle.asn1.DERSequence;
031:
032: /**
033: * ASN.1 structure DER En/DeCoder.
034: *
035: * <pre>
036: * PKIPublicationInfo ::= SEQUENCE {
037: * action INTEGER {
038: * dontPublish (0),
039: * pleasePublish (1) },
040: * pubInfos SEQUENCE SIZE (1..MAX) OF SinglePubInfo OPTIONAL } -- pubInfos MUST NOT be present if action is "dontPublish" (if action is "pleasePublish" and pubInfos is omitted, "dontCare" is assumed)
041: *
042: * </pre>
043: */
044: public class PKIPublicationInfo implements DEREncodable {
045: DERInteger action;
046: Vector pubInfos = new Vector();
047:
048: public static PKIPublicationInfo getInstance(ASN1TaggedObject obj,
049: boolean explicit) {
050: return getInstance(ASN1Sequence.getInstance(obj, explicit));
051: }
052:
053: public static PKIPublicationInfo getInstance(Object obj) {
054: if (obj instanceof PKIPublicationInfo) {
055: return (PKIPublicationInfo) obj;
056: } else if (obj instanceof ASN1Sequence) {
057: return new PKIPublicationInfo((ASN1Sequence) obj);
058: }
059:
060: throw new IllegalArgumentException("unknown object in factory");
061: }
062:
063: public PKIPublicationInfo(ASN1Sequence seq) {
064: this .action = DERInteger.getInstance(seq.getObjectAt(0));
065: if (seq.size() > 1) {
066: ASN1Sequence s = (ASN1Sequence) seq.getObjectAt(1);
067: for (int i = 0; i < s.size(); i++)
068: pubInfos.addElement(SinglePubInfo.getInstance(s
069: .getObjectAt(i)));
070: }
071: }
072:
073: public PKIPublicationInfo(DERInteger action) {
074: this .action = action;
075: }
076:
077: public DERInteger getAction() {
078: return action;
079: }
080:
081: public SinglePubInfo getPubInfo(int nr) {
082: if (pubInfos.size() > nr)
083: return (SinglePubInfo) pubInfos.elementAt(nr);
084:
085: return null;
086: }
087:
088: public void addPubInfo(SinglePubInfo pubInfo) {
089: pubInfos.addElement(pubInfo);
090: }
091:
092: public DERObject getDERObject() {
093: ASN1EncodableVector v = new ASN1EncodableVector();
094:
095: v.add(action);
096:
097: if (pubInfos.size() > 0) {
098: ASN1EncodableVector pubiv = new ASN1EncodableVector();
099: for (int i = 0; i < pubInfos.size(); i++)
100: pubiv.add((SinglePubInfo) pubInfos.elementAt(i));
101:
102: v.add(new DERSequence(pubiv));
103: }
104:
105: return new DERSequence(v);
106: }
107:
108: public String toString() {
109: String s = "PKIPublicationInfo: (action = " + this .getAction();
110:
111: if (pubInfos.size() > 0) {
112: s += "pubInfos : (";
113:
114: for (int i = 0; i < pubInfos.size(); i++)
115: s += (SinglePubInfo) pubInfos.elementAt(i);
116:
117: s += ")";
118: }
119:
120: s += ")";
121:
122: return s;
123: }
124: }
|