package org.bouncycastle.openpgp.api.exception;

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

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

    public InvalidEncryptionKeyException(OpenPGPCertificate openPGPCertificate) {
        super(openPGPCertificate, "Certificate " + openPGPCertificate.getKeyIdentifier() + " does not contain any usable subkeys capable of encryption.");
    }

    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 encryption.").toString();
    }
}
