001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander V. Astapchuk
020: * @version $Revision$
021: */package java.security;
022:
023: import java.io.Serializable;
024: import java.security.cert.CertPath;
025:
026: import org.apache.harmony.security.internal.nls.Messages;
027:
028: /**
029: * @com.intel.drl.spec_ref
030: */
031:
032: public final class CodeSigner implements Serializable {
033:
034: /**
035: * @com.intel.drl.spec_ref
036: */
037: private static final long serialVersionUID = 6819288105193937581L;
038:
039: /**
040: * @com.intel.drl.spec_ref
041: */
042: private CertPath signerCertPath;
043:
044: /**
045: * @com.intel.drl.spec_ref
046: */
047: private Timestamp timestamp;
048:
049: // Cached hash code value
050: private transient int hash;
051:
052: /**
053: * @com.intel.drl.spec_ref
054: */
055: public CodeSigner(CertPath signerCertPath, Timestamp timestamp) {
056: if (signerCertPath == null) {
057: throw new NullPointerException(Messages
058: .getString("security.10")); //$NON-NLS-1$
059: }
060: this .signerCertPath = signerCertPath;
061: this .timestamp = timestamp;
062: }
063:
064: /**
065: * @com.intel.drl.spec_ref
066: */
067: public boolean equals(Object obj) {
068: if (obj == this ) {
069: return true;
070: }
071: if (obj instanceof CodeSigner) {
072: CodeSigner that = (CodeSigner) obj;
073: if (!signerCertPath.equals(that.signerCertPath)) {
074: return false;
075: }
076: return timestamp == null ? that.timestamp == null
077: : timestamp.equals(that.timestamp);
078: }
079: return false;
080: }
081:
082: /**
083: * @com.intel.drl.spec_ref
084: */
085: public CertPath getSignerCertPath() {
086: return signerCertPath;
087: }
088:
089: /**
090: * @com.intel.drl.spec_ref
091: */
092: public Timestamp getTimestamp() {
093: return timestamp;
094: }
095:
096: /**
097: * @com.intel.drl.spec_ref
098: */
099: public int hashCode() {
100: if (hash == 0) {
101: hash = signerCertPath.hashCode()
102: ^ (timestamp == null ? 0 : timestamp.hashCode());
103: }
104: return hash;
105: }
106:
107: /**
108: * @com.intel.drl.spec_ref
109: */
110: public String toString() {
111: // There is no any special reason for '256' here, it's taken abruptly
112: // FIXME: 1.5 StringBuffer => StringBuilder
113: StringBuffer buf = new StringBuffer(256);
114: // The javadoc says nothing, and the others implementations behavior seems as
115: // dumping only the first certificate. Well, let's do the same.
116: buf
117: .append("CodeSigner [").append(signerCertPath.getCertificates().get(0)); //$NON-NLS-1$
118: if (timestamp != null) {
119: buf.append("; ").append(timestamp); //$NON-NLS-1$
120: }
121: buf.append("]"); //$NON-NLS-1$
122: return buf.toString();
123: }
124: }
|