1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package java.security; 19 20 /** 21 * {@link Signer} represents an identity (individual or corporation) that owns a 22 * private key and the corresponding public key. 23 * 24 * @deprecated Replaced by behavior in {@link java.security.cert 25 * java.security.cert} package and {@link java.security.Principal 26 * Principal} 27 */ 28 @Deprecated 29 public abstract class Signer extends Identity { 30 31 private static final long serialVersionUID = -1763464102261361480L; 32 33 private PrivateKey privateKey; 34 35 /** 36 * Constructs a new instance of {@code Signer}. 37 */ 38 protected Signer() { 39 } 40 41 /** 42 * Constructs a new instance of {@code Signer} with the given name. 43 * 44 * @param name 45 * the name of the signer. 46 */ 47 public Signer(String name) { 48 super(name); 49 } 50 51 /** 52 * Constructs a new instance of {@code Signer} with the given name in the 53 * given scope. 54 * 55 * @param name 56 * the name of the signer. 57 * @param scope 58 * the scope of the signer. 59 * @throws KeyManagementException 60 * if a signer with the specified name already exists in the 61 * provided scope. 62 */ 63 public Signer(String name, IdentityScope scope) throws KeyManagementException { 64 super(name, scope); 65 } 66 67 /** 68 * Returns the private key of this {@code Signer}. 69 */ 70 public PrivateKey getPrivateKey() { 71 return privateKey; 72 } 73 74 /** 75 * Associates the specified key pair with this {@code Signer}. 76 * 77 * @param pair 78 * the key pair to associate with this {@code Signer}. 79 * @throws InvalidParameterException 80 * if the key pair is invalid. 81 * @throws KeyException 82 * if any other key related problem occurs. 83 */ 84 public final void setKeyPair(KeyPair pair) throws InvalidParameterException, KeyException { 85 if (pair == null) { 86 throw new NullPointerException("pair == null"); 87 } 88 89 if (pair.getPrivate() == null || pair.getPublic() == null) { 90 throw new InvalidParameterException(); 91 } 92 setPublicKey(pair.getPublic()); 93 this.privateKey = pair.getPrivate(); 94 } 95 96 /** 97 * Returns a string containing a concise, human-readable description of this 98 * {@code Signer} including its name and its scope if present. 99 * 100 * @return a printable representation for this {@code Signer}. 101 */ 102 @Override 103 public String toString() { 104 String s = "[Signer]" + getName(); 105 if (getScope() != null) { 106 s = s + '[' + getScope().toString() + ']'; 107 } 108 return s; 109 } 110 } 111