Home | History | Annotate | Download | only in x509
      1 /*
      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
      8  *
      9  *     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 
     22 /**
     23  * This class implements the values of Subject Alternative Name
     24  * (OID is 2.5.29.17) and Issuer Alternative Name extensions
     25  * (OID is 2.5.29.18).<br>
     26  * For more information about these extensions see RFC 3280
     27  * at http://www.ietf.org/rfc/rfc3280.txt
     28  */
     29 public final class AlternativeName extends ExtensionValue {
     30 
     31     // constants indicating which alternative name is presented
     32     // by this object
     33     public static final boolean ISSUER = false;
     34     public static final boolean SUBJECT = true;
     35 
     36     /** indicating which alternative name is presented by this object */
     37     private boolean which;
     38     /** the alternative names */
     39     private GeneralNames alternativeNames;
     40 
     41     /**
     42      * Creates the extension object on the base of its encoded form.
     43      * @param which specifies which alternative names are given
     44      * (Subject's or Issuer's)
     45      */
     46     public AlternativeName(boolean which, byte[] encoding) throws IOException {
     47         super(encoding);
     48         this.which = which;
     49         this.alternativeNames = (GeneralNames) GeneralNames.ASN1.decode(encoding);
     50     }
     51 
     52     /**
     53      * Returns ASN.1 encoded form of this X.509 AlternativeName value.
     54      */
     55     @Override public byte[] getEncoded() {
     56         if (encoding == null) {
     57             encoding = GeneralNames.ASN1.encode(alternativeNames);
     58         }
     59         return encoding;
     60     }
     61 
     62     @Override public void dumpValue(StringBuilder sb, String prefix) {
     63         sb.append(prefix).append((which) ? "Subject" : "Issuer").append(" Alternative Names [\n");
     64         alternativeNames.dumpValue(sb, prefix + "  ");
     65         sb.append(prefix).append("]\n");
     66     }
     67 }
     68