blob: b0368061e1a7ee2720b35a2a565423f58fa193d8 (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2007, 2012 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
* and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.osgi.internal.signedcontent;
import java.security.cert.Certificate;
import org.eclipse.osgi.signedcontent.SignerInfo;
public class SignerInfoImpl implements SignerInfo {
private final Certificate[] chain;
private final String mdAlgorithm;
volatile private Certificate trustAnchor;
public SignerInfoImpl(Certificate[] chain, Certificate trustAnchor, String mdAlgorithm) {
this.chain = chain;
this.trustAnchor = trustAnchor;
this.mdAlgorithm = mdAlgorithm;
}
public Certificate[] getCertificateChain() {
return chain;
}
public Certificate getTrustAnchor() {
return trustAnchor;
}
public boolean isTrusted() {
return trustAnchor != null;
}
void setTrustAnchor(Certificate trustAnchor) {
this.trustAnchor = trustAnchor;
}
public String getMessageDigestAlgorithm() {
return mdAlgorithm;
}
public int hashCode() {
int result = mdAlgorithm.hashCode();
for (int i = 0; i < chain.length; i++)
result += chain[i].hashCode();
// Note that we do not hash based on trustAnchor;
// this changes dynamically but we need a constant hashCode for purposes of
// hashing in a Set.
return result;
}
public boolean equals(Object obj) {
if (!(obj instanceof SignerInfo))
return false;
if (obj == this)
return true;
SignerInfo other = (SignerInfo) obj;
if (!mdAlgorithm.equals(other.getMessageDigestAlgorithm()))
return false;
Certificate[] otherCerts = other.getCertificateChain();
if (otherCerts.length != chain.length)
return false;
for (int i = 0; i < chain.length; i++)
if (!chain[i].equals(otherCerts[i]))
return false;
return trustAnchor == null ? other.getTrustAnchor() == null : trustAnchor.equals(other.getTrustAnchor());
}
}
|