1 /*
2  * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package sun.security.x509;
27 
28 import java.io.IOException;
29 
30 import sun.security.util.*;
31 
32 /**
33  * This interface specifies the abstract methods which have to be
34  * implemented by all the members of the GeneralNames ASN.1 object.
35  *
36  * @author Amit Kapoor
37  * @author Hemma Prafullchandra
38  */
39 public interface GeneralNameInterface {
40     /**
41      * The list of names supported.
42      */
43     public static final int NAME_ANY = 0;
44     public static final int NAME_RFC822 = 1;
45     public static final int NAME_DNS = 2;
46     public static final int NAME_X400 = 3;
47     public static final int NAME_DIRECTORY = 4;
48     public static final int NAME_EDI = 5;
49     public static final int NAME_URI = 6;
50     public static final int NAME_IP = 7;
51     public static final int NAME_OID = 8;
52 
53     /**
54      * The list of constraint results.
55      */
56     public static final int NAME_DIFF_TYPE = -1; /* input name is different type from name (i.e. does not constrain) */
57     public static final int NAME_MATCH = 0;      /* input name matches name */
58     public static final int NAME_NARROWS = 1;    /* input name narrows name */
59     public static final int NAME_WIDENS = 2;     /* input name widens name */
60     public static final int NAME_SAME_TYPE = 3;  /* input name does not match, narrow, or widen, but is same type */
61 
62     /**
63      * Return the type of the general name, as
64      * defined above.
65      */
getType()66     int getType();
67 
68     /**
69      * Encode the name to the specified DerOutputStream.
70      *
71      * @param out the DerOutputStream to encode the GeneralName to.
72      * @exception IOException thrown if the GeneralName could not be
73      *            encoded.
74      */
encode(DerOutputStream out)75     void encode(DerOutputStream out) throws IOException;
76 
77     /**
78      * Return type of constraint inputName places on this name:<ul>
79      *   <li>NAME_DIFF_TYPE = -1: input name is different type from name (i.e. does not constrain).
80      *   <li>NAME_MATCH = 0: input name matches name.
81      *   <li>NAME_NARROWS = 1: input name narrows name (is lower in the naming subtree)
82      *   <li>NAME_WIDENS = 2: input name widens name (is higher in the naming subtree)
83      *   <li>NAME_SAME_TYPE = 3: input name does not match or narrow name, but is same type.
84      * </ul>.  These results are used in checking NameConstraints during
85      * certification path verification.
86      *
87      * @param inputName to be checked for being constrained
88      * @return constraint type above
89      * @throws UnsupportedOperationException if name is same type, but comparison operations are
90      *          not supported for this name type.
91      */
constrains(GeneralNameInterface inputName)92     int constrains(GeneralNameInterface inputName) throws UnsupportedOperationException;
93 
94     /**
95      * Return subtree depth of this name for purposes of determining
96      * NameConstraints minimum and maximum bounds and for calculating
97      * path lengths in name subtrees.
98      *
99      * @return distance of name from root
100      * @throws UnsupportedOperationException if not supported for this name type
101      */
subtreeDepth()102     int subtreeDepth() throws UnsupportedOperationException;
103 }
104