1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package java.security;
import java.io.Serializable;
import java.security.cert.CertPath;
/**
* {@code CodeSigner} represents a signer of code. Instances are immutable.
*/
public final class CodeSigner implements Serializable {
private static final long serialVersionUID = 6819288105193937581L;
private CertPath signerCertPath;
private Timestamp timestamp;
// Cached hash code value
private transient int hash;
/**
* Constructs a new instance of {@code CodeSigner}.
*
* @param signerCertPath
* the certificate path associated with this code signer.
* @param timestamp
* the time stamp associated with this code signer, maybe {@code
* null}.
* @throws NullPointerException
* if {@code signerCertPath} is {@code null}.
*/
public CodeSigner(CertPath signerCertPath, Timestamp timestamp) {
if (signerCertPath == null) {
throw new NullPointerException("signerCertPath == null");
}
this.signerCertPath = signerCertPath;
this.timestamp = timestamp;
}
/**
* Compares the specified object with this {@code CodeSigner} for equality.
* Returns {@code true} if the specified object is also an instance of
* {@code CodeSigner}, the two {@code CodeSigner} encapsulate the same
* certificate path and the same time stamp, if present in both.
*
* @param obj
* object to be compared for equality with this {@code
* CodeSigner}.
* @return {@code true} if the specified object is equal to this {@code
* CodeSigner}, otherwise {@code false}.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CodeSigner) {
CodeSigner that = (CodeSigner) obj;
if (!signerCertPath.equals(that.signerCertPath)) {
return false;
}
return timestamp == null ? that.timestamp == null : timestamp
.equals(that.timestamp);
}
return false;
}
/**
* Returns the certificate path associated with this {@code CodeSigner}.
*
* @return the certificate path associated with this {@code CodeSigner}.
*/
public CertPath getSignerCertPath() {
return signerCertPath;
}
/**
* Returns the time stamp associated with this {@code CodeSigner}.
*
* @return the time stamp associated with this {@code CodeSigner}, maybe
* {@code null}.
*/
public Timestamp getTimestamp() {
return timestamp;
}
/**
* Returns the hash code value for this {@code CodeSigner}. Returns the same
* hash code for {@code CodeSigner}s that are equal to each other as
* required by the general contract of {@link Object#hashCode}.
*
* @return the hash code value for this {@code CodeSigner}.
* @see Object#equals(Object)
* @see CodeSigner#equals(Object)
*/
@Override
public int hashCode() {
if (hash == 0) {
hash = signerCertPath.hashCode()
^ (timestamp == null ? 0 : timestamp.hashCode());
}
return hash;
}
/**
* Returns a string containing a concise, human-readable description of the
* this {@code CodeSigner} including its first certificate and its time
* stamp, if present.
*
* @return a printable representation for this {@code CodeSigner}.
*/
@Override
public String toString() {
// There is no any special reason for '256' here, it's taken abruptly
StringBuilder buf = new StringBuilder(256);
// The javadoc says nothing, and the others implementations behavior seems as
// dumping only the first certificate. Well, let's do the same.
buf.append("CodeSigner [").append(signerCertPath.getCertificates().get(0));
if( timestamp != null ) {
buf.append("; ").append(timestamp);
}
buf.append("]");
return buf.toString();
}
}
|