KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > crmf > PKIPublicationInfo


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.crmf;
21
22 import java.util.Vector JavaDoc;
23
24 import org.bouncycastle.asn1.ASN1EncodableVector;
25 import org.bouncycastle.asn1.ASN1Sequence;
26 import org.bouncycastle.asn1.ASN1TaggedObject;
27 import org.bouncycastle.asn1.DEREncodable;
28 import org.bouncycastle.asn1.DERInteger;
29 import org.bouncycastle.asn1.DERObject;
30 import org.bouncycastle.asn1.DERSequence;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  * PKIPublicationInfo ::= SEQUENCE {
37  * action INTEGER {
38  * dontPublish (0),
39  * pleasePublish (1) },
40  * 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)
41  *
42  * </pre>
43  */

44 public class PKIPublicationInfo implements DEREncodable
45 {
46     DERInteger action;
47     Vector JavaDoc pubInfos = new Vector JavaDoc();
48
49     public static PKIPublicationInfo getInstance( ASN1TaggedObject obj, boolean explicit )
50     {
51         return getInstance(ASN1Sequence.getInstance(obj, explicit));
52     }
53
54     public static PKIPublicationInfo getInstance( Object JavaDoc obj )
55     {
56         if (obj instanceof PKIPublicationInfo)
57         {
58             return (PKIPublicationInfo)obj;
59         }
60         else if (obj instanceof ASN1Sequence)
61         {
62             return new PKIPublicationInfo((ASN1Sequence)obj);
63         }
64
65         throw new IllegalArgumentException JavaDoc("unknown object in factory");
66     }
67     
68     public PKIPublicationInfo( ASN1Sequence seq )
69     {
70       this.action = DERInteger.getInstance(seq.getObjectAt(0));
71       if( seq.size()>1 )
72       {
73         ASN1Sequence s = (ASN1Sequence)seq.getObjectAt(1);
74         for( int i=0; i<s.size(); i++ )
75           pubInfos.addElement( SinglePubInfo.getInstance(s.getObjectAt(i)) );
76       }
77     }
78
79     public PKIPublicationInfo( DERInteger action )
80     {
81       this.action = action;
82     }
83
84     public DERInteger getAction()
85     {
86         return action;
87     }
88
89     public SinglePubInfo getPubInfo(int nr)
90     {
91       if( pubInfos.size() > nr )
92         return (SinglePubInfo)pubInfos.elementAt(nr);
93         
94       return null;
95     }
96
97     public void addPubInfo(SinglePubInfo pubInfo)
98     {
99       pubInfos.addElement( pubInfo );
100     }
101
102     public DERObject getDERObject()
103     {
104       ASN1EncodableVector v = new ASN1EncodableVector();
105
106       v.add( action );
107
108       if( pubInfos.size() > 0 )
109       {
110         ASN1EncodableVector pubiv = new ASN1EncodableVector();
111         for (int i=0;i<pubInfos.size();i++)
112           pubiv.add( (SinglePubInfo)pubInfos.elementAt(i) );
113           
114         v.add( new DERSequence( pubiv ) );
115       }
116
117       return new DERSequence(v);
118     }
119
120     public String JavaDoc toString()
121     {
122       String JavaDoc s = "PKIPublicationInfo: (action = " + this.getAction();
123       
124       if( pubInfos.size() > 0 )
125       {
126         s += "pubInfos : (";
127         
128         for (int i=0;i<pubInfos.size();i++)
129           s += (SinglePubInfo)pubInfos.elementAt(i);
130           
131         s += ")";
132       }
133
134       s += ")";
135       
136       return s;
137     }
138 }
139
Popular Tags