KickJava   Java API By Example, From Geeks To Geeks.

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


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.DERObject;
30 import org.bouncycastle.asn1.DERSequence;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  * POPODecKeyChallContent ::= SEQUENCE OF Challenge -- One Challenge per encryption key certification request (in the same order as these requests appear in CertReqMessages).
37  * </pre>
38  */

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