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.crmf;
21:
22: import java.util.Vector;
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.DERObject;
29: import org.bouncycastle.asn1.DERSequence;
30:
31: /**
32: * ASN.1 structure DER En/DeCoder.
33: *
34: * <pre>
35: * CertReqMessages ::= SEQUENCE SIZE (1..MAX) OF CertReqMsg
36: *
37: * </pre>
38: */
39: public class CertReqMessages implements DEREncodable {
40: Vector certReqMsgs = new Vector();
41:
42: public static CertReqMessages getInstance(ASN1TaggedObject obj,
43: boolean explicit) {
44: return getInstance(ASN1Sequence.getInstance(obj, explicit));
45: }
46:
47: public static CertReqMessages getInstance(Object obj) {
48: if (obj instanceof CertReqMessages) {
49: return (CertReqMessages) obj;
50: } else if (obj instanceof ASN1Sequence) {
51: return new CertReqMessages((ASN1Sequence) obj);
52: }
53:
54: throw new IllegalArgumentException("unknown object in factory");
55: }
56:
57: public CertReqMessages(ASN1Sequence seq) {
58: for (int i = 0; i < seq.size(); i++)
59: certReqMsgs.addElement(CertReqMsg.getInstance(seq
60: .getObjectAt(i)));
61: }
62:
63: public CertReqMessages(CertReqMsg certReqMsg) {
64: certReqMsgs.addElement(certReqMsg);
65: }
66:
67: public CertReqMsg getCertReqMsg(int nr) {
68: if (certReqMsgs.size() > nr)
69: return (CertReqMsg) certReqMsgs.elementAt(nr);
70:
71: return null;
72: }
73:
74: public void addCertReqMsg(CertReqMsg certReqMsg) {
75: certReqMsgs.addElement(certReqMsg);
76: }
77:
78: public DERObject getDERObject() {
79:
80: ASN1EncodableVector v = new ASN1EncodableVector();
81:
82: for (int i = 0; i < certReqMsgs.size(); i++)
83: v.add((CertReqMsg) certReqMsgs.elementAt(i));
84:
85: return new DERSequence(v);
86: }
87:
88: public String toString() {
89: String s = "CertReqMessages: (";
90:
91: for (int i = 0; i < certReqMsgs.size(); i++)
92: s += (CertReqMsg) certReqMsgs.elementAt(i);
93:
94: s += ")";
95:
96: return s;
97: }
98: }
|