View Javadoc

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;
23  
24  import org.bouncycastle.asn1.ASN1Encodable;
25  import org.bouncycastle.asn1.ASN1EncodableVector;
26  import org.bouncycastle.asn1.ASN1Integer;
27  import org.bouncycastle.asn1.ASN1Primitive;
28  import org.bouncycastle.asn1.ASN1Sequence;
29  import org.bouncycastle.asn1.ASN1TaggedObject;
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 ASN1Encodable
45  {
46  	ASN1Integer   action;
47      Vector       pubInfos = new Vector();
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 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("unknown object in factory");
66      }
67  	
68      public PKIPublicationInfo( ASN1Sequence seq )
69      {
70        this.action = ASN1Integer.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  
80      public PKIPublicationInfo( ASN1Integer action )
81      {
82        this.action = action;
83      }
84  
85      public ASN1Integer getAction()
86      {
87          return action;
88      }
89  
90      public SinglePubInfo getPubInfo(int nr)
91      {
92        if( pubInfos.size() > nr ) {
93          return (SinglePubInfo)pubInfos.elementAt(nr);
94        }
95        return null;
96      }
97  
98      public void addPubInfo(SinglePubInfo pubInfo)
99      {
100       pubInfos.addElement( pubInfo );
101     }
102 
103     public ASN1Primitive toASN1Primitive()
104     {
105       ASN1EncodableVector  v = new ASN1EncodableVector();
106 
107       v.add( action );
108 
109       if( pubInfos.size() > 0 )
110       {
111         ASN1EncodableVector pubiv = new ASN1EncodableVector();
112         for (int i=0;i<pubInfos.size();i++) {
113           pubiv.add( (SinglePubInfo)pubInfos.elementAt(i) );
114         }
115         v.add( new DERSequence( pubiv ) );
116       }
117 
118       return new DERSequence(v);
119     }
120 
121     public String toString()
122     {
123       String s = "PKIPublicationInfo: (action = " + this.getAction();
124       
125       if( pubInfos.size() > 0 )
126       {
127         s += "pubInfos : (";
128         
129         for (int i=0;i<pubInfos.size();i++) {
130           s += (SinglePubInfo)pubInfos.elementAt(i);
131         }
132         s += ")";
133       }
134 
135       s += ")";
136       
137       return s;
138     }
139 }