@Override
public void setCertificateChain(final X509Certificate[] certificateChain) {
if (certificateChain == null || certificateChain.length == 0) {
this.certificateChain = null;
this.certificateChainAsBcObjects = null;
return;
}
this.certificateChain = certificateChain;
setPublicKey(certificateChain[0].getPublicKey());
final int n = certificateChain.length;
this.certificateChainAsBcObjects = new X509CertificateHolder[n];
for (int i = 0; i < n; i++) {
X509Certificate cert = this.certificateChain[i];
try {
this.certificateChainAsBcObjects[i] = new X509CertificateHolder(cert.getEncoded());
} catch (CertificateEncodingException | IOException ex) {
throw new IllegalArgumentException(
String.format("%s occurred while parsing certificate at index %d: %s",
ex.getClass().getName(), i, ex.getMessage()), ex);
}
}
}