1
2package org.bouncycastle.asn1.x509;
3
4import java.util.Enumeration;
5import java.util.Vector;
6
7import org.bouncycastle.asn1.ASN1Encodable;
8import org.bouncycastle.asn1.ASN1EncodableVector;
9import org.bouncycastle.asn1.ASN1Sequence;
10import org.bouncycastle.asn1.DERInteger;
11import org.bouncycastle.asn1.DERObject;
12import org.bouncycastle.asn1.DERSequence;
13
14/**
15 * <code>NoticeReference</code> class, used in
16 * <code>CertificatePolicies</code> X509 V3 extensions
17 * (in policy qualifiers).
18 *
19 * <pre>
20 *  NoticeReference ::= SEQUENCE {
21 *      organization     DisplayText,
22 *      noticeNumbers    SEQUENCE OF INTEGER }
23 *
24 * </pre>
25 *
26 * @see PolicyQualifierInfo
27 * @see PolicyInformation
28 */
29public class NoticeReference
30    extends ASN1Encodable
31{
32   private DisplayText organization;
33   private ASN1Sequence noticeNumbers;
34
35   /**
36    * Creates a new <code>NoticeReference</code> instance.
37    *
38    * @param orgName a <code>String</code> value
39    * @param numbers a <code>Vector</code> value
40    */
41   public NoticeReference(
42       String orgName,
43       Vector numbers)
44   {
45      organization = new DisplayText(orgName);
46
47      Object o = numbers.elementAt(0);
48
49      ASN1EncodableVector av = new ASN1EncodableVector();
50      if (o instanceof Integer)
51      {
52         Enumeration it = numbers.elements();
53
54         while (it.hasMoreElements())
55         {
56            Integer nm = (Integer) it.nextElement();
57               DERInteger di = new DERInteger(nm.intValue());
58            av.add (di);
59         }
60      }
61
62      noticeNumbers = new DERSequence(av);
63   }
64
65   /**
66    * Creates a new <code>NoticeReference</code> instance.
67    *
68    * @param orgName a <code>String</code> value
69    * @param numbers an <code>ASN1EncodableVector</code> value
70    */
71   public NoticeReference(
72       String orgName,
73       ASN1Sequence numbers)
74   {
75       organization = new DisplayText (orgName);
76       noticeNumbers = numbers;
77   }
78
79   /**
80    * Creates a new <code>NoticeReference</code> instance.
81    *
82    * @param displayTextType an <code>int</code> value
83    * @param orgName a <code>String</code> value
84    * @param numbers an <code>ASN1EncodableVector</code> value
85    */
86   public NoticeReference(
87       int displayTextType,
88       String orgName,
89       ASN1Sequence numbers)
90   {
91       organization = new DisplayText(displayTextType,
92                                     orgName);
93       noticeNumbers = numbers;
94   }
95
96   /**
97    * Creates a new <code>NoticeReference</code> instance.
98    * <p>Useful for reconstructing a <code>NoticeReference</code>
99    * instance from its encodable/encoded form.
100    *
101    * @param as an <code>ASN1Sequence</code> value obtained from either
102    * calling @{link toASN1Object()} for a <code>NoticeReference</code>
103    * instance or from parsing it from a DER-encoded stream.
104    */
105   public NoticeReference(
106       ASN1Sequence as)
107   {
108       if (as.size() != 2)
109       {
110            throw new IllegalArgumentException("Bad sequence size: "
111                    + as.size());
112       }
113
114       organization = DisplayText.getInstance(as.getObjectAt(0));
115       noticeNumbers = ASN1Sequence.getInstance(as.getObjectAt(1));
116   }
117
118   public static NoticeReference getInstance(
119       Object as)
120   {
121      if (as instanceof NoticeReference)
122      {
123          return (NoticeReference)as;
124      }
125      else if (as instanceof ASN1Sequence)
126      {
127          return new NoticeReference((ASN1Sequence)as);
128      }
129
130      throw new IllegalArgumentException("unknown object in getInstance.");
131   }
132
133   public DisplayText getOrganization()
134   {
135       return organization;
136   }
137
138   public ASN1Sequence getNoticeNumbers()
139   {
140       return noticeNumbers;
141   }
142
143   /**
144    * Describe <code>toASN1Object</code> method here.
145    *
146    * @return a <code>DERObject</code> value
147    */
148   public DERObject toASN1Object()
149   {
150      ASN1EncodableVector av = new ASN1EncodableVector();
151      av.add (organization);
152      av.add (noticeNumbers);
153      return new DERSequence (av);
154   }
155}
156