summaryrefslogtreecommitdiffstats
path: root/base/util/src/netscape/security/x509/LdapDNStrConverter.java
blob: a8cb878136fbce6abf783d26a1431001cf15e5a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package netscape.security.x509;

import java.io.IOException;

/**
 * Abstract class that converts a Ldap DN String to an X500Name, RDN or AVA
 * and vice versa, except the string is a java string in unicode.
 * 
 * @author Lily Hsiao, Slava Galperin at Netscape Communications, Inc.
 */

public abstract class LdapDNStrConverter {
    // 
    // public parsing methods.
    //

    /**
     * Converts a Ldap DN string to a X500Name object.
     * 
     * @param dn a Ldap DN String.
     * 
     * @return an X500Name object for the Ldap DN String.
     */
    public abstract X500Name parseDN(String dn)
            throws IOException;

    /**
     * Like parseDN with a specified DER encoding order for Directory Strings.
     */
    public abstract X500Name parseDN(String dn, byte[] tags)
            throws IOException;

    /**
     * Converts a Ldap DN string to a RDN object.
     * 
     * @param rdn a Ldap DN String
     * 
     * @return an RDN object.
     */
    public abstract RDN parseRDN(String rdn)
            throws IOException;

    /**
     * Like parseRDN with a specified DER encoding order for Directory Strings.
     */
    public abstract RDN parseRDN(String rdn, byte[] tags)
            throws IOException;

    /**
     * Converts a Ldap DN string to a AVA object.
     * 
     * @param ava a Ldap DN string.
     * @return an AVA object.
     */
    public abstract AVA parseAVA(String ava)
            throws IOException;

    /**
     * Like parseAVA with a specified DER encoding order for Directory Strings.
     */
    public abstract AVA parseAVA(String rdn, byte[] tags)
            throws IOException;

    //
    // public encoding methods.
    //

    /**
     * Converts a X500Name object to a Ldap dn string.
     * 
     * @param dn an X500Name object.
     * @return a Ldap DN String.
     */
    public abstract String encodeDN(X500Name dn) throws IOException;

    /**
     * Converts an RDN object to a Ldap dn string.
     * 
     * @param rdn an RDN object.
     * @return a Ldap dn string.
     */
    public abstract String encodeRDN(RDN rdn) throws IOException;

    /**
     * Converts an AVA object to a Ldap dn string.
     * 
     * @param ava An AVA object.
     * @return A Ldap dn string.
     */
    public abstract String encodeAVA(AVA ava) throws IOException;

    //
    // public static methods
    //

    /**
     * Gets a global default Ldap DN String converter.
     * Currently it is LdapV3DNStrConverter object using the default
     * X500NameAttrMap and accepts unknown OIDs.
     * 
     * @see netscape.security.x509.LdapV3DNStrConverter
     * 
     * @return The global default LdapDNStrConverter instance.
     */
    public static LdapDNStrConverter getDefault() {
        return defaultConverter;
    }

    /**
     * Set the global default LdapDNStrConverter object.
     * 
     * @param defConverter A LdapDNStrConverter object to become
     *            the global default.
     */
    public static void setDefault(LdapDNStrConverter defConverter) {
        if (defConverter == null)
            throw new IllegalArgumentException(
                    "The default Ldap DN String converter cannot be set to null.");
        defaultConverter = defConverter;
    }

    //
    // private static variables
    //

    private static LdapDNStrConverter defaultConverter = new LdapV3DNStrConverter();
}