01: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
02: //
03: // Author: Maik Stohn
04: //
05: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
06: // software and associated documentation files (the "Software"), to deal in the Software
07: // without restriction, including without limitation the rights to use, copy, modify, merge,
08: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
09: // 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;
23: import java.util.Vector;
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: Vector challenges = new Vector();
41:
42: public static POPODecKeyChallContent getInstance(
43: ASN1TaggedObject obj, boolean explicit) {
44: return getInstance(ASN1Sequence.getInstance(obj, explicit));
45: }
46:
47: public static POPODecKeyChallContent getInstance(Object obj) {
48: if (obj instanceof POPODecKeyChallContent) {
49: return (POPODecKeyChallContent) obj;
50: } else if (obj instanceof ASN1Sequence) {
51: return new POPODecKeyChallContent((ASN1Sequence) obj);
52: }
53:
54: throw new IllegalArgumentException("unknown object in factory");
55: }
56:
57: public POPODecKeyChallContent(ASN1Sequence seq) {
58: Enumeration e = seq.getObjects();
59:
60: while (e.hasMoreElements())
61: challenges.addElement(Challenge
62: .getInstance(e.nextElement()));
63: }
64:
65: public POPODecKeyChallContent(Challenge p) {
66: challenges.addElement(p);
67: }
68:
69: public void addChallenge(Challenge p) {
70: challenges.addElement(p);
71: }
72:
73: public Challenge getChallenge(int nr) {
74: if (challenges.size() > nr)
75: return (Challenge) challenges.elementAt(nr);
76:
77: return null;
78: }
79:
80: public DERObject getDERObject() {
81: ASN1EncodableVector v = new ASN1EncodableVector();
82:
83: for (int i = 0; i < challenges.size(); i++)
84: v.add((Challenge) challenges.elementAt(i));
85:
86: return new DERSequence(v);
87: }
88:
89: public String toString() {
90: String s = "POPODecKeyChallContent: (";
91:
92: for (int i = 0; i < challenges.size(); i++)
93: s += challenges.elementAt(i) + ", ";
94:
95: s += ")";
96:
97: return s;
98: }
99: }
|