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