package org.bouncycastle.openpgp.api.exception;

import org.bouncycastle.bcpg.KeyIdentifier;
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
import org.bouncycastle.openpgp.api.OpenPGPKey;

/* JADX INFO: loaded from: classes3.dex */
public class InvalidSigningKeyException extends OpenPGPKeyException {
    public InvalidSigningKeyException(OpenPGPCertificate.OpenPGPComponentKey openPGPComponentKey) {
        super(openPGPComponentKey, componentKeyErrorMessage(openPGPComponentKey));
    }

    public InvalidSigningKeyException(OpenPGPKey openPGPKey) {
        super(openPGPKey, "The key " + openPGPKey.getKeyIdentifier() + " does not contain any usable component keys capable of signing.");
    }

    private static String componentKeyErrorMessage(OpenPGPCertificate.OpenPGPComponentKey openPGPComponentKey) {
        StringBuilder sbAppend;
        KeyIdentifier keyIdentifier;
        if (openPGPComponentKey.getKeyIdentifier().equals(openPGPComponentKey.getCertificate().getKeyIdentifier())) {
            sbAppend = new StringBuilder().append("The primary key ");
            keyIdentifier = openPGPComponentKey.getKeyIdentifier();
        } else {
            sbAppend = new StringBuilder().append("The subkey ").append(openPGPComponentKey.getKeyIdentifier()).append(" from the certificate ");
            keyIdentifier = openPGPComponentKey.getCertificate().getKeyIdentifier();
        }
        return sbAppend.append(keyIdentifier).append(" is not usable for signing.").toString();
    }
}
