01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERSequence;
08:
09: /**
10: * <code>UserNotice</code> class, used in
11: * <code>CertificatePolicies</code> X509 extensions (in policy
12: * qualifiers).
13: * <pre>
14: * UserNotice ::= SEQUENCE {
15: * noticeRef NoticeReference OPTIONAL,
16: * explicitText DisplayText OPTIONAL}
17: *
18: * </pre>
19: *
20: * @see PolicyQualifierId
21: * @see PolicyInformation
22: */
23: public class UserNotice extends ASN1Encodable {
24: private NoticeReference noticeRef;
25: private DisplayText explicitText;
26:
27: /**
28: * Creates a new <code>UserNotice</code> instance.
29: *
30: * @param noticeRef a <code>NoticeReference</code> value
31: * @param explicitText a <code>DisplayText</code> value
32: */
33: public UserNotice(NoticeReference noticeRef,
34: DisplayText explicitText) {
35: this .noticeRef = noticeRef;
36: this .explicitText = explicitText;
37: }
38:
39: /**
40: * Creates a new <code>UserNotice</code> instance.
41: *
42: * @param noticeRef a <code>NoticeReference</code> value
43: * @param str the explicitText field as a String.
44: */
45: public UserNotice(NoticeReference noticeRef, String str) {
46: this .noticeRef = noticeRef;
47: this .explicitText = new DisplayText(str);
48: }
49:
50: /**
51: * Creates a new <code>UserNotice</code> instance.
52: * <p>Useful from reconstructing a <code>UserNotice</code> instance
53: * from its encodable/encoded form.
54: *
55: * @param as an <code>ASN1Sequence</code> value obtained from either
56: * calling @{link toASN1Object()} for a <code>UserNotice</code>
57: * instance or from parsing it from a DER-encoded stream.
58: */
59: public UserNotice(ASN1Sequence as) {
60: if (as.size() == 2) {
61: noticeRef = NoticeReference.getInstance(as.getObjectAt(0));
62: explicitText = DisplayText.getInstance(as.getObjectAt(1));
63: } else if (as.size() == 1) {
64: if (as.getObjectAt(0).getDERObject() instanceof ASN1Sequence) {
65: noticeRef = NoticeReference.getInstance(as
66: .getObjectAt(0));
67: } else {
68: explicitText = DisplayText.getInstance(as
69: .getObjectAt(0));
70: }
71: } else {
72: throw new IllegalArgumentException("Bad sequence size: "
73: + as.size());
74: }
75: }
76:
77: public NoticeReference getNoticeRef() {
78: return noticeRef;
79: }
80:
81: public DisplayText getExplicitText() {
82: return explicitText;
83: }
84:
85: public DERObject toASN1Object() {
86: ASN1EncodableVector av = new ASN1EncodableVector();
87:
88: if (noticeRef != null) {
89: av.add(noticeRef);
90: }
91:
92: if (explicitText != null) {
93: av.add(explicitText);
94: }
95:
96: return new DERSequence(av);
97: }
98: }
|