jdk/src/java.base/share/classes/sun/security/x509/GeneralName.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
child 30369 26cd8124a0a4
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class implements the ASN.1 GeneralName object class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The ASN.1 syntax for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * GeneralName ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *    otherName                       [0]     OtherName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *    rfc822Name                      [1]     IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *    dNSName                         [2]     IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *    x400Address                     [3]     ORAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *    directoryName                   [4]     Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *    ediPartyName                    [5]     EDIPartyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *    uniformResourceIdentifier       [6]     IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *    iPAddress                       [7]     OCTET STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    registeredID                    [8]     OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class GeneralName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Private data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private GeneralNameInterface name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Default constructor for the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param name the selected CHOICE from the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @throws NullPointerException if name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public GeneralName(GeneralNameInterface name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            throw new NullPointerException("GeneralName must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Create the object from its DER encoded value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param encName the DER encoded GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public GeneralName(DerValue encName) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this(encName, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Create the object from its DER encoded value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param encName the DER encoded GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param nameConstraint true if general name is a name constraint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public GeneralName(DerValue encName, boolean nameConstraint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        short tag = (byte)(encName.tag & 0x1f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // All names except for NAME_DIRECTORY should be encoded with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // IMPLICIT tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        case GeneralNameInterface.NAME_ANY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (encName.isContextSpecific() && encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                encName.resetTag(DerValue.tag_Sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                name = new OtherName(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                throw new IOException("Invalid encoding of Other-Name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        case GeneralNameInterface.NAME_RFC822:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (encName.isContextSpecific() && !encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                encName.resetTag(DerValue.tag_IA5String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                name = new RFC822Name(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                throw new IOException("Invalid encoding of RFC822 name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        case GeneralNameInterface.NAME_DNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (encName.isContextSpecific() && !encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                encName.resetTag(DerValue.tag_IA5String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                name = new DNSName(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                throw new IOException("Invalid encoding of DNS name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        case GeneralNameInterface.NAME_URI:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (encName.isContextSpecific() && !encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                encName.resetTag(DerValue.tag_IA5String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                name = (nameConstraint ? URIName.nameConstraint(encName) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        new URIName(encName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                throw new IOException("Invalid encoding of URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        case GeneralNameInterface.NAME_IP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (encName.isContextSpecific() && !encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                encName.resetTag(DerValue.tag_OctetString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                name = new IPAddressName(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                throw new IOException("Invalid encoding of IP address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        case GeneralNameInterface.NAME_OID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (encName.isContextSpecific() && !encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                encName.resetTag(DerValue.tag_ObjectId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                name = new OIDName(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                throw new IOException("Invalid encoding of OID name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        case GeneralNameInterface.NAME_DIRECTORY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (encName.isContextSpecific() && encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                name = new X500Name(encName.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                throw new IOException("Invalid encoding of Directory name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        case GeneralNameInterface.NAME_EDI:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (encName.isContextSpecific() && encName.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                encName.resetTag(DerValue.tag_Sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                name = new EDIPartyName(encName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                throw new IOException("Invalid encoding of EDI name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new IOException("Unrecognized GeneralName tag, ("
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                  + tag +")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Return the type of the general name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return name.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Return the GeneralNameInterface name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public GeneralNameInterface getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        //XXXX May want to consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Return the name as user readable string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return name.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Compare this GeneralName with another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param other GeneralName to compare to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @returns true if match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (!(other instanceof GeneralName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        GeneralNameInterface otherGNI = ((GeneralName)other).name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return name.constrains(otherGNI) == GeneralNameInterface.NAME_MATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (UnsupportedOperationException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Returns the hash code for this GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return a hash code value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Encode the name to the specified DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   224
     * @param out the DerOutputStream to encode the GeneralName to.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        name.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int nameType = name.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (nameType == GeneralNameInterface.NAME_ANY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            nameType == GeneralNameInterface.NAME_X400 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            nameType == GeneralNameInterface.NAME_EDI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // implicit, constructed form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            out.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                              true, (byte)nameType), tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else if (nameType == GeneralNameInterface.NAME_DIRECTORY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            // explicit, constructed form since underlying tag is CHOICE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // (see X.680 section 30.6, part c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                         true, (byte)nameType), tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            // implicit, primitive form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            out.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                              false, (byte)nameType), tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}