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;
}
@Override
public Certificate[] getCertificateChain() {
return chain;
}
@Override
public Certificate getTrustAnchor() {
return trustAnchor;
}
@Override
public boolean isTrusted() {
return trustAnchor != null;
}
void setTrustAnchor(Certificate trustAnchor) {
this.trustAnchor = trustAnchor;
}
@Override
public String getMessageDigestAlgorithm() {
return mdAlgorithm;
}
@Override
public int hashCode() {
int result = mdAlgorithm.hashCode();
for (Certificate cert : chain) {
result += cert.hashCode();
}
return result;
}
@Override
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());
}
}