001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.crypto.asn1.x509;
017:
018: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
019: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
020: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
021: import org.apache.geronimo.crypto.asn1.DERObject;
022: import org.apache.geronimo.crypto.asn1.DERSequence;
023:
024: /**
025: * <code>UserNotice</code> class, used in
026: * <code>CertificatePolicies</code> X509 extensions (in policy
027: * qualifiers).
028: * <pre>
029: * UserNotice ::= SEQUENCE {
030: * noticeRef NoticeReference OPTIONAL,
031: * explicitText DisplayText OPTIONAL}
032: *
033: * </pre>
034: *
035: * @see PolicyQualifierId
036: * @see PolicyInformation
037: */
038: public class UserNotice extends ASN1Encodable {
039: NoticeReference noticeRef;
040: DisplayText explicitText;
041:
042: /**
043: * Creates a new <code>UserNotice</code> instance.
044: *
045: * @param noticeRef a <code>NoticeReference</code> value
046: * @param explicitText a <code>DisplayText</code> value
047: */
048: public UserNotice(NoticeReference noticeRef,
049: DisplayText explicitText) {
050: this .noticeRef = noticeRef;
051: this .explicitText = explicitText;
052: }
053:
054: /**
055: * Creates a new <code>UserNotice</code> instance.
056: *
057: * @param noticeRef a <code>NoticeReference</code> value
058: * @param str the explicitText field as a String.
059: */
060: public UserNotice(NoticeReference noticeRef, String str) {
061: this .noticeRef = noticeRef;
062: this .explicitText = new DisplayText(str);
063: }
064:
065: /**
066: * Creates a new <code>UserNotice</code> instance.
067: * <p>Useful from reconstructing a <code>UserNotice</code> instance
068: * from its encodable/encoded form.
069: *
070: * @param as an <code>ASN1Sequence</code> value obtained from either
071: * calling @{link toASN1Object()} for a <code>UserNotice</code>
072: * instance or from parsing it from a DER-encoded stream.
073: */
074: public UserNotice(ASN1Sequence as) {
075: if (as.size() == 2) {
076: noticeRef = NoticeReference.getInstance(as.getObjectAt(0));
077: explicitText = DisplayText.getInstance(as.getObjectAt(1));
078: } else if (as.size() == 1) {
079: if (as.getObjectAt(0).getDERObject() instanceof ASN1Sequence) {
080: noticeRef = NoticeReference.getInstance(as
081: .getObjectAt(0));
082: } else {
083: explicitText = DisplayText.getInstance(as
084: .getObjectAt(0));
085: }
086: }
087: }
088:
089: public DERObject toASN1Object() {
090: ASN1EncodableVector av = new ASN1EncodableVector();
091:
092: if (noticeRef != null) {
093: av.add(noticeRef);
094: }
095:
096: if (explicitText != null) {
097: av.add(explicitText);
098: }
099:
100: return new DERSequence(av);
101: }
102: }
|