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 * Basic implementation of {@link X500DNHandler} which uses the internal built-in mechanisms
23 * provided by {@link X500Principal} directly.
24 */
25 public class InternalX500DNHandler implements X500DNHandler {
26
27 /** {@inheritDoc} */
28 public byte[] getEncoded(X500Principal principal) {
29 if (principal == null) {
30 throw new NullPointerException("X500Principal may not be null");
31 }
32 return principal.getEncoded();
33 }
34
35 /** {@inheritDoc} */
36 public String getName(X500Principal principal) {
37 if (principal == null) {
38 throw new NullPointerException("X500Principal may not be null");
39 }
40 return principal.getName();
41 }
42
43 /** {@inheritDoc} */
44 public String getName(X500Principal principal, String format) {
45 if (principal == null) {
46 throw new NullPointerException("X500Principal may not be null");
47 }
48 return principal.getName(format);
49 }
50
51 /** {@inheritDoc} */
52 public X500Principal parse(String name) {
53 if (name == null) {
54 throw new NullPointerException("X.500 name string may not be null");
55 }
56 return new X500Principal(name);
57 }
58
59 /** {@inheritDoc} */
60 public X500Principal parse(byte[] name) {
61 if (name == null) {
62 throw new NullPointerException("X.500 DER-encoded name may not be null");
63 }
64 return new X500Principal(name);
65 }
66
67 /** {@inheritDoc} */
68 public X500DNHandler clone() {
69 // We don't have any state, just return a new instance to maintain the clone() contract.
70 return new InternalX500DNHandler();
71 }
72
73 }