1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.geronimo.util.asn1.x509; 20 21 import org.apache.geronimo.util.asn1.ASN1Encodable; 22 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 23 import org.apache.geronimo.util.asn1.ASN1Sequence; 24 import org.apache.geronimo.util.asn1.DERObject; 25 import org.apache.geronimo.util.asn1.DERSequence; 26 27 /** 28 * <code>UserNotice</code> class, used in 29 * <code>CertificatePolicies</code> X509 extensions (in policy 30 * qualifiers). 31 * <pre> 32 * UserNotice ::= SEQUENCE { 33 * noticeRef NoticeReference OPTIONAL, 34 * explicitText DisplayText OPTIONAL} 35 * 36 * </pre> 37 * 38 * @see PolicyQualifierId 39 * @see PolicyInformation 40 */ 41 public class UserNotice 42 extends ASN1Encodable 43 { 44 NoticeReference noticeRef; 45 DisplayText explicitText; 46 47 /** 48 * Creates a new <code>UserNotice</code> instance. 49 * 50 * @param noticeRef a <code>NoticeReference</code> value 51 * @param explicitText a <code>DisplayText</code> value 52 */ 53 public UserNotice( 54 NoticeReference noticeRef, 55 DisplayText explicitText) 56 { 57 this.noticeRef = noticeRef; 58 this.explicitText = explicitText; 59 } 60 61 /** 62 * Creates a new <code>UserNotice</code> instance. 63 * 64 * @param noticeRef a <code>NoticeReference</code> value 65 * @param str the explicitText field as a String. 66 */ 67 public UserNotice( 68 NoticeReference noticeRef, 69 String str) 70 { 71 this.noticeRef = noticeRef; 72 this.explicitText = new DisplayText(str); 73 } 74 75 /** 76 * Creates a new <code>UserNotice</code> instance. 77 * <p>Useful from reconstructing a <code>UserNotice</code> instance 78 * from its encodable/encoded form. 79 * 80 * @param as an <code>ASN1Sequence</code> value obtained from either 81 * calling @{link toASN1Object()} for a <code>UserNotice</code> 82 * instance or from parsing it from a DER-encoded stream. 83 */ 84 public UserNotice( 85 ASN1Sequence as) 86 { 87 if (as.size() == 2) 88 { 89 noticeRef = NoticeReference.getInstance(as.getObjectAt(0)); 90 explicitText = DisplayText.getInstance(as.getObjectAt(1)); 91 } 92 else if (as.size() == 1) 93 { 94 if (as.getObjectAt(0).getDERObject() instanceof ASN1Sequence) 95 { 96 noticeRef = NoticeReference.getInstance(as.getObjectAt(0)); 97 } 98 else 99 { 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 }