01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERSequence;
08:
09: public class GeneralNames extends ASN1Encodable {
10: ASN1Sequence seq;
11:
12: public static GeneralNames getInstance(Object obj) {
13: if (obj == null || obj instanceof GeneralNames) {
14: return (GeneralNames) obj;
15: }
16:
17: if (obj instanceof ASN1Sequence) {
18: return new GeneralNames((ASN1Sequence) obj);
19: }
20:
21: throw new IllegalArgumentException(
22: "illegal object in getInstance: "
23: + obj.getClass().getName());
24: }
25:
26: public static GeneralNames getInstance(ASN1TaggedObject obj,
27: boolean explicit) {
28: return getInstance(ASN1Sequence.getInstance(obj, explicit));
29: }
30:
31: /**
32: * Construct a GeneralNames object containing one GeneralName.
33: *
34: * @param name the name to be contained.
35: */
36: public GeneralNames(GeneralName name) {
37: this .seq = new DERSequence(name);
38: }
39:
40: public GeneralNames(ASN1Sequence seq) {
41: this .seq = seq;
42: }
43:
44: public GeneralName[] getNames() {
45: GeneralName[] names = new GeneralName[seq.size()];
46:
47: for (int i = 0; i != seq.size(); i++) {
48: names[i] = GeneralName.getInstance(seq.getObjectAt(i));
49: }
50:
51: return names;
52: }
53:
54: /**
55: * Produce an object suitable for an ASN1OutputStream.
56: * <pre>
57: * GeneralNames ::= SEQUENCE SIZE {1..MAX} OF GeneralName
58: * </pre>
59: */
60: public DERObject toASN1Object() {
61: return seq;
62: }
63:
64: public String toString() {
65: StringBuffer buf = new StringBuffer();
66: String sep = System.getProperty("line.separator");
67: GeneralName[] names = getNames();
68:
69: buf.append("GeneralNames:");
70: buf.append(sep);
71:
72: for (int i = 0; i != names.length; i++) {
73: buf.append(" ");
74: buf.append(names[i]);
75: buf.append(sep);
76: }
77: return buf.toString();
78: }
79: }
|