01: package org.bouncycastle.asn1.cmp;
02:
03: import java.util.Enumeration;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1Sequence;
07: import org.bouncycastle.asn1.ASN1TaggedObject;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERUTF8String;
11:
12: public class PKIFreeText extends ASN1Encodable {
13: ASN1Sequence strings;
14:
15: public static PKIFreeText getInstance(ASN1TaggedObject obj,
16: boolean explicit) {
17: return getInstance(ASN1Sequence.getInstance(obj, explicit));
18: }
19:
20: public static PKIFreeText getInstance(Object obj) {
21: if (obj instanceof PKIFreeText) {
22: return (PKIFreeText) obj;
23: } else if (obj instanceof ASN1Sequence) {
24: return new PKIFreeText((ASN1Sequence) obj);
25: }
26:
27: throw new IllegalArgumentException("Unknown object in factory");
28: }
29:
30: public PKIFreeText(ASN1Sequence seq) {
31: Enumeration e = seq.getObjects();
32: while (e.hasMoreElements()) {
33: if (!(e.nextElement() instanceof DERUTF8String)) {
34: throw new IllegalArgumentException(
35: "attempt to insert non UTF8 STRING into PKIFreeText");
36: }
37: }
38:
39: strings = seq;
40: }
41:
42: public PKIFreeText(DERUTF8String p) {
43: strings = new DERSequence(p);
44: }
45:
46: /**
47: * Return the number of string elements present.
48: *
49: * @return number of elements present.
50: */
51: public int size() {
52: return strings.size();
53: }
54:
55: /**
56: * Return the UTF8STRING at index i.
57: *
58: * @param i index of the string of interest
59: * @return the string at index i.
60: */
61: public DERUTF8String getStringAt(int i) {
62: return (DERUTF8String) strings.getObjectAt(i);
63: }
64:
65: /**
66: * <pre>
67: * PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
68: * </pre>
69: */
70: public DERObject toASN1Object() {
71: return strings;
72: }
73: }
|