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.util.Date;
025: import java.security.cert.CertPath;
026:
027: import org.apache.harmony.security.internal.nls.Messages;
028:
029: /**
030: * @com.intel.drl.spec_ref
031: */
032:
033: public final class Timestamp implements Serializable {
034:
035: /**
036: * @com.intel.drl.spec_ref
037: */
038: private static final long serialVersionUID = -5502683707821851294L;
039:
040: private Date timestamp;
041:
042: private CertPath signerCertPath;
043:
044: // Cached hash
045: private transient int hash;
046:
047: /**
048: * @com.intel.drl.spec_ref
049: */
050: public Timestamp(Date timestamp, CertPath signerCertPath) {
051: if (timestamp == null) {
052: throw new NullPointerException(Messages
053: .getString("security.0F")); //$NON-NLS-1$
054: }
055: if (signerCertPath == null) {
056: throw new NullPointerException(Messages
057: .getString("security.10")); //$NON-NLS-1$
058: }
059: // Clone timestamp to prevent modifications
060: this .timestamp = new Date(timestamp.getTime());
061: this .signerCertPath = signerCertPath;
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 Timestamp) {
072: Timestamp that = (Timestamp) obj;
073: return timestamp.equals(that.timestamp)
074: && signerCertPath.equals(that.signerCertPath);
075: }
076: return false;
077: }
078:
079: /**
080: * @com.intel.drl.spec_ref
081: */
082: public CertPath getSignerCertPath() {
083: return signerCertPath;
084: }
085:
086: /**
087: * @com.intel.drl.spec_ref
088: */
089: public Date getTimestamp() {
090: return (Date) timestamp.clone();
091: }
092:
093: /**
094: * @com.intel.drl.spec_ref
095: */
096: public int hashCode() {
097: if (hash == 0) {
098: hash = timestamp.hashCode() ^ signerCertPath.hashCode();
099: }
100: return hash;
101: }
102:
103: /**
104: * @com.intel.drl.spec_ref
105: */
106: public String toString() {
107: StringBuffer buf = new StringBuffer(256);
108: // Dump only the first certificate
109: buf
110: .append("Timestamp [").append(timestamp).append(" certPath="); //$NON-NLS-1$ //$NON-NLS-2$
111: buf.append(signerCertPath.getCertificates().get(0)).append("]"); //$NON-NLS-1$
112: return buf.toString();
113: }
114: }
|