001: package org.bouncycastle.asn1.x509;
002:
003: import java.util.Enumeration;
004: import java.util.Vector;
005:
006: import org.bouncycastle.asn1.ASN1Encodable;
007: import org.bouncycastle.asn1.ASN1EncodableVector;
008: import org.bouncycastle.asn1.ASN1Sequence;
009: import org.bouncycastle.asn1.DERInteger;
010: import org.bouncycastle.asn1.DERObject;
011: import org.bouncycastle.asn1.DERSequence;
012:
013: /**
014: * <code>NoticeReference</code> class, used in
015: * <code>CertificatePolicies</code> X509 V3 extensions
016: * (in policy qualifiers).
017: *
018: * <pre>
019: * NoticeReference ::= SEQUENCE {
020: * organization DisplayText,
021: * noticeNumbers SEQUENCE OF INTEGER }
022: *
023: * </pre>
024: *
025: * @see PolicyQualifierInfo
026: * @see PolicyInformation
027: */
028: public class NoticeReference extends ASN1Encodable {
029: private DisplayText organization;
030: private ASN1Sequence noticeNumbers;
031:
032: /**
033: * Creates a new <code>NoticeReference</code> instance.
034: *
035: * @param orgName a <code>String</code> value
036: * @param numbers a <code>Vector</code> value
037: */
038: public NoticeReference(String orgName, Vector numbers) {
039: organization = new DisplayText(orgName);
040:
041: Object o = numbers.elementAt(0);
042:
043: ASN1EncodableVector av = new ASN1EncodableVector();
044: if (o instanceof Integer) {
045: Enumeration it = numbers.elements();
046:
047: while (it.hasMoreElements()) {
048: Integer nm = (Integer) it.nextElement();
049: DERInteger di = new DERInteger(nm.intValue());
050: av.add(di);
051: }
052: }
053:
054: noticeNumbers = new DERSequence(av);
055: }
056:
057: /**
058: * Creates a new <code>NoticeReference</code> instance.
059: *
060: * @param orgName a <code>String</code> value
061: * @param numbers an <code>ASN1EncodableVector</code> value
062: */
063: public NoticeReference(String orgName, ASN1Sequence numbers) {
064: organization = new DisplayText(orgName);
065: noticeNumbers = numbers;
066: }
067:
068: /**
069: * Creates a new <code>NoticeReference</code> instance.
070: *
071: * @param displayTextType an <code>int</code> value
072: * @param orgName a <code>String</code> value
073: * @param numbers an <code>ASN1EncodableVector</code> value
074: */
075: public NoticeReference(int displayTextType, String orgName,
076: ASN1Sequence numbers) {
077: organization = new DisplayText(displayTextType, orgName);
078: noticeNumbers = numbers;
079: }
080:
081: /**
082: * Creates a new <code>NoticeReference</code> instance.
083: * <p>Useful for reconstructing a <code>NoticeReference</code>
084: * instance from its encodable/encoded form.
085: *
086: * @param as an <code>ASN1Sequence</code> value obtained from either
087: * calling @{link toASN1Object()} for a <code>NoticeReference</code>
088: * instance or from parsing it from a DER-encoded stream.
089: */
090: public NoticeReference(ASN1Sequence as) {
091: if (as.size() != 2) {
092: throw new IllegalArgumentException("Bad sequence size: "
093: + as.size());
094: }
095:
096: organization = DisplayText.getInstance(as.getObjectAt(0));
097: noticeNumbers = ASN1Sequence.getInstance(as.getObjectAt(1));
098: }
099:
100: public static NoticeReference getInstance(Object as) {
101: if (as instanceof NoticeReference) {
102: return (NoticeReference) as;
103: } else if (as instanceof ASN1Sequence) {
104: return new NoticeReference((ASN1Sequence) as);
105: }
106:
107: throw new IllegalArgumentException(
108: "unknown object in getInstance.");
109: }
110:
111: public DisplayText getOrganization() {
112: return organization;
113: }
114:
115: public ASN1Sequence getNoticeNumbers() {
116: return noticeNumbers;
117: }
118:
119: /**
120: * Describe <code>toASN1Object</code> method here.
121: *
122: * @return a <code>DERObject</code> value
123: */
124: public DERObject toASN1Object() {
125: ASN1EncodableVector av = new ASN1EncodableVector();
126: av.add(organization);
127: av.add(noticeNumbers);
128: return new DERSequence(av);
129: }
130: }
|