1 /*
2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.opensaml.xml.security.x509;
18
19 import javax.security.auth.x500.X500Principal;
20
21 /**
22 * Interface for implementations which handle parsing and serialization of X.500 names
23 * represented by {@link X500Principal}.
24 */
25 public interface X500DNHandler {
26
27 /** Specifies the string format specified in RFC 1779. */
28 public static final String FORMAT_RFC1779 = X500Principal.RFC1779;
29
30 /** Specifies the string format specified in RFC 2253. */
31 public static final String FORMAT_RFC2253 = X500Principal.RFC2253;
32
33 /**
34 * Parse the string representation of a name and build a new principal instance.
35 *
36 * @param name the name string to parse
37 * @return a new principal instance
38 *
39 * @throws IllegalArgumentException if the name value can not be parsed by the implementation
40 */
41 public X500Principal parse(String name);
42
43 /**
44 * Parse the ASN.1 DER encoding representation of a name and build a new principal instance.
45 *
46 * @param name a distinguished name in ASN.1 DER encoded form
47 * @return a new principal instance
48 *
49 * @throws IllegalArgumentException if the name value can not be parsed by the implementation
50 */
51 public X500Principal parse(byte[] name);
52
53 /**
54 * Returns a string representation of the X.500 distinguished name using the default format
55 * as defined in the underlying implementation.
56 *
57 * @param principal the principal name instance to serialize
58 * @return the serialized string name
59 */
60 public String getName(X500Principal principal);
61
62 /**
63 * Returns a string representation of the X.500 distinguished name using the specified format.
64 *
65 * The values and meanings of the format specifier are implementation dependent. Constants for
66 * two common standard formats are provided here as {@link #FORMAT_RFC1779} and {@link #FORMAT_RFC2253};
67 *
68 * @param principal the principal name instance to serialize
69 * @param format the format specifier of the resulting serialized string name
70 * @return the serialized string name
71 *
72 * @throws IllegalArgumentException if the specified format is not understood by the implementation
73 */
74 public String getName(X500Principal principal, String format);
75
76 /**
77 * Returns the distinguished name in ASN.1 DER encoded form.
78 *
79 * @param principal the principal name instance to serialize
80 * @return the serialized name in ASN.1 DER encoded form
81 */
82 public byte[] getEncoded(X500Principal principal);
83
84 /**
85 * Clone the handler. Implementations which maintain instance-specific configuration data, etc,
86 * should implement this appropriately, possibly also implementing {@link Cloneable}.
87 *
88 * @return the cloned handler
89 */
90 public X500DNHandler clone();
91
92 }