KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > cmp > POPODecKeyRespContent


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.cmp;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import org.bouncycastle.asn1.ASN1EncodableVector;
26 import org.bouncycastle.asn1.ASN1Sequence;
27 import org.bouncycastle.asn1.ASN1TaggedObject;
28 import org.bouncycastle.asn1.DEREncodable;
29 import org.bouncycastle.asn1.DERInteger;
30 import org.bouncycastle.asn1.DERObject;
31 import org.bouncycastle.asn1.DERSequence;
32
33 /**
34  * ASN.1 structure DER En/DeCoder.
35  *
36  * <pre>
37  * POPODecKeyRespContent ::= SEQUENCE OF INTEGER -- One INTEGER per encryption key certification request (in the same order as these requests appear in CertReqMessages). The
38  * -- retrieved INTEGER A (above) is returned to the sender of the corresponding Challenge.
39  * </pre>
40  */

41 public class POPODecKeyRespContent implements DEREncodable
42 {
43   Vector JavaDoc integers = new Vector JavaDoc();
44
45   public static POPODecKeyRespContent getInstance(ASN1TaggedObject obj, boolean explicit)
46   {
47     return getInstance(ASN1Sequence.getInstance(obj, explicit));
48   }
49
50   public static POPODecKeyRespContent getInstance(Object JavaDoc obj)
51   {
52     if (obj instanceof POPODecKeyRespContent)
53     {
54       return (POPODecKeyRespContent) obj;
55     }
56     else if (obj instanceof ASN1Sequence)
57     {
58       return new POPODecKeyRespContent((ASN1Sequence) obj);
59     }
60
61     throw new IllegalArgumentException JavaDoc("unknown object in factory");
62   }
63
64   public POPODecKeyRespContent(ASN1Sequence seq)
65   {
66     Enumeration JavaDoc e = seq.getObjects();
67
68     while (e.hasMoreElements())
69       integers.addElement( e.nextElement() );
70   }
71
72   public POPODecKeyRespContent(DERInteger p)
73   {
74     integers.addElement(p);
75   }
76
77   public void addInteger(DERInteger p)
78   {
79     integers.addElement(p);
80   }
81
82   public DERInteger getInteger(int nr)
83   {
84     if (integers.size() > nr)
85       return (DERInteger) integers.elementAt(nr);
86
87     return null;
88   }
89
90   public DERObject getDERObject()
91   {
92     ASN1EncodableVector v = new ASN1EncodableVector();
93
94     for (int i = 0; i < integers.size(); i++)
95       v.add((DERInteger) integers.elementAt(i));
96
97     return new DERSequence(v);
98   }
99
100   public String JavaDoc toString()
101   {
102     String JavaDoc s = "POPODecKeyRespContent: (";
103     
104     for (int i=0;i<integers.size();i++)
105       s += integers.elementAt(i) + ", ";
106     
107     s += ")";
108     
109     return s;
110   }
111 }
112
Popular Tags