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