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