Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/security/CodeSigner.java
38829 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import java.io.*;28import java.security.cert.CertPath;2930/**31* This class encapsulates information about a code signer.32* It is immutable.33*34* @since 1.535* @author Vincent Ryan36*/3738public final class CodeSigner implements Serializable {3940private static final long serialVersionUID = 6819288105193937581L;4142/**43* The signer's certificate path.44*45* @serial46*/47private CertPath signerCertPath;4849/*50* The signature timestamp.51*52* @serial53*/54private Timestamp timestamp;5556/*57* Hash code for this code signer.58*/59private transient int myhash = -1;6061/**62* Constructs a CodeSigner object.63*64* @param signerCertPath The signer's certificate path.65* It must not be {@code null}.66* @param timestamp A signature timestamp.67* If {@code null} then no timestamp was generated68* for the signature.69* @throws NullPointerException if {@code signerCertPath} is70* {@code null}.71*/72public CodeSigner(CertPath signerCertPath, Timestamp timestamp) {73if (signerCertPath == null) {74throw new NullPointerException();75}76this.signerCertPath = signerCertPath;77this.timestamp = timestamp;78}7980/**81* Returns the signer's certificate path.82*83* @return A certificate path.84*/85public CertPath getSignerCertPath() {86return signerCertPath;87}8889/**90* Returns the signature timestamp.91*92* @return The timestamp or {@code null} if none is present.93*/94public Timestamp getTimestamp() {95return timestamp;96}9798/**99* Returns the hash code value for this code signer.100* The hash code is generated using the signer's certificate path and the101* timestamp, if present.102*103* @return a hash code value for this code signer.104*/105public int hashCode() {106if (myhash == -1) {107if (timestamp == null) {108myhash = signerCertPath.hashCode();109} else {110myhash = signerCertPath.hashCode() + timestamp.hashCode();111}112}113return myhash;114}115116/**117* Tests for equality between the specified object and this118* code signer. Two code signers are considered equal if their119* signer certificate paths are equal and if their timestamps are equal,120* if present in both.121*122* @param obj the object to test for equality with this object.123*124* @return true if the objects are considered equal, false otherwise.125*/126public boolean equals(Object obj) {127if (obj == null || (!(obj instanceof CodeSigner))) {128return false;129}130CodeSigner that = (CodeSigner)obj;131132if (this == that) {133return true;134}135Timestamp thatTimestamp = that.getTimestamp();136if (timestamp == null) {137if (thatTimestamp != null) {138return false;139}140} else {141if (thatTimestamp == null ||142(! timestamp.equals(thatTimestamp))) {143return false;144}145}146return signerCertPath.equals(that.getSignerCertPath());147}148149/**150* Returns a string describing this code signer.151*152* @return A string comprising the signer's certificate and a timestamp,153* if present.154*/155public String toString() {156StringBuffer sb = new StringBuffer();157sb.append("(");158sb.append("Signer: " + signerCertPath.getCertificates().get(0));159if (timestamp != null) {160sb.append("timestamp: " + timestamp);161}162sb.append(")");163return sb.toString();164}165166// Explicitly reset hash code value to -1167private void readObject(ObjectInputStream ois)168throws IOException, ClassNotFoundException {169ois.defaultReadObject();170myhash = -1;171}172}173174175