2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Alexander Y. Kleymenov
23 package org.apache.harmony.security.x509;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Iterator;
28 import java.util.List;
29 import org.apache.harmony.security.asn1.ASN1SequenceOf;
30 import org.apache.harmony.security.asn1.ASN1Type;
31 import org.apache.harmony.security.asn1.BerInputStream;
35 * The class encapsulates the ASN.1 DER encoding/decoding work
36 * with the GeneralNames structure which is a part of X.509 certificate
37 * (as specified in RFC 3280 -
38 * Internet X.509 Public Key Infrastructure.
39 * Certificate and Certificate Revocation List (CRL) Profile.
40 * http://www.ietf.org/rfc/rfc3280.txt):
44 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
47 * @see org.apache.harmony.security.x509.NameConstraints
48 * @see org.apache.harmony.security.x509.GeneralSubtree
50 public class GeneralNames {
52 // the values of GeneralName
53 private List generalNames;
54 // the ASN.1 encoded form of GeneralNames
55 private byte[] encoding;
58 * Constructs an object representing the value of GeneralNames.
60 public GeneralNames() {
61 generalNames = new ArrayList();
66 * @param generalNames: List
68 public GeneralNames(List generalNames) {
69 this.generalNames = generalNames;
74 // @param generalNames: List
75 // @param encoding: byte[]
77 private GeneralNames(List generalNames, byte[] encoding) {
78 this.generalNames = generalNames;
79 this.encoding = encoding;
83 * Returns the list of values.
86 public List getNames() {
87 if ((generalNames == null) || (generalNames.size() == 0)) {
90 return new ArrayList(generalNames);
94 * Returns the collection of pairs: (Integer (tag), Object (name value))*
95 * @return the collection of pairs: (Integer (tag), Object (name value))*
97 public List getPairsList() {
98 ArrayList result = new ArrayList();
99 if (generalNames == null) {
102 Iterator it = generalNames.iterator();
103 while (it.hasNext()) {
104 result.add(((GeneralName) it.next()).getAsList());
111 * @param name: GeneralName
114 public void addName(GeneralName name) {
116 if (generalNames == null) {
117 generalNames = new ArrayList();
119 generalNames.add(name);
124 * @param name: GeneralName
127 public GeneralName getNameByTag(int tag) {
129 if ((generalNames == null) || (generalNames.size() == 0)) {
132 for (int i=0; i<generalNames.size(); i++) {
133 if (((GeneralName) generalName.get(i)).getTag() == tag) {
136 generalNames.add(name);
141 * Returns ASN.1 encoded form of this X.509 GeneralNames value.
142 * @return a byte array containing ASN.1 encode form.
144 public byte[] getEncoded() {
145 if (encoding == null) {
146 encoding = ASN1.encode(this);
152 * Places the string representation of extension value
153 * into the StringBuffer object.
155 public void dumpValue(StringBuffer buffer, String prefix) {
156 if (generalNames == null) {
159 for (Iterator it=generalNames.iterator(); it.hasNext();) {
160 buffer.append(prefix);
161 buffer.append(it.next());
167 * ASN.1 DER X.509 GeneralNames encoder/decoder class.
169 public static final ASN1Type ASN1 = new ASN1SequenceOf(GeneralName.ASN1) {
171 public Object getDecodedObject(BerInputStream in) {
172 return new GeneralNames((List)in.content, in.getEncoded());
175 public Collection getValues(Object object) {
176 GeneralNames gns = (GeneralNames) object;
177 return gns.generalNames;