01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
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.
16: */
17:
18: package org.apache.harmony.security.x509;
19:
20: import java.io.IOException;
21: import java.util.List;
22:
23: /**
24: * This class implements the values of Subject Alternative Name
25: * (OID is 2.5.29.17) and Issuer Alternative Name extensions
26: * (OID is 2.5.29.18).<br>
27: * For more information about these extensions see RFC 3280
28: * at http://www.ietf.org/rfc/rfc3280.txt
29: */
30: public class AlternativeName extends ExtensionValue {
31:
32: // constants indicating which alternative name is presented
33: // by this object
34: public static final boolean ISSUER = false;
35: public static final boolean SUBJECT = true;
36:
37: // indicating which alternative name is presented by this object
38: private boolean which;
39: // the alternative names
40: private GeneralNames alternativeNames;
41:
42: /**
43: * Creates the extension object for given alternative names.
44: * @param which specifies which alternative names are given
45: * (Subject's or Issuer's)
46: */
47: public AlternativeName(boolean which, GeneralNames alternativeNames) {
48: this .which = which;
49: this .alternativeNames = alternativeNames;
50: }
51:
52: /**
53: * Creates the extension object on the base of its encoded form.
54: * @param which specifies which alternative names are given
55: * (Subject's or Issuer's)
56: */
57: public AlternativeName(boolean which, byte[] encoding)
58: throws IOException {
59: super (encoding);
60: this .which = which;
61: this .alternativeNames = (GeneralNames) GeneralNames.ASN1
62: .decode(encoding);
63: }
64:
65: /**
66: * Returns the list of alternative names.
67: * The list is in the collection of pairs:<br>
68: * [Integer (tag of GeneralName), Object (name value)]
69: */
70: public List getAlternativeNames() {
71: return alternativeNames.getPairsList();
72: }
73:
74: /**
75: * Returns ASN.1 encoded form of this X.509 AlternativeName value.
76: * @return a byte array containing ASN.1 encode form.
77: */
78: public byte[] getEncoded() {
79: if (encoding == null) {
80: encoding = GeneralNames.ASN1.encode(alternativeNames);
81: }
82: return encoding;
83: }
84:
85: /**
86: * Places the string representation of extension value
87: * into the StringBuffer object.
88: */
89: public void dumpValue(StringBuffer buffer, String prefix) {
90: buffer.append(prefix).append((which) ? "Subject" : "Issuer") //$NON-NLS-1$ //$NON-NLS-2$
91: .append(" Alternative Names [\n"); //$NON-NLS-1$
92: alternativeNames.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
93: buffer.append(prefix).append("]\n"); //$NON-NLS-1$
94: }
95: }
|