return null-cryptors for unprotected keys

This commit is contained in:
Paul Schaub 2020-01-14 22:10:07 +01:00
parent 4b61745c46
commit 9c1f6fc812
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 9 additions and 7 deletions

View File

@ -55,18 +55,20 @@ public class PasswordBasedSecretKeyRingProtector implements SecretKeyRingProtect
@Nullable
public PBESecretKeyDecryptor getDecryptor(Long keyId) {
Passphrase passphrase = passphraseProvider.getPassphraseFor(keyId);
return new BcPBESecretKeyDecryptorBuilder(calculatorProvider)
.build(passphrase != null ? passphrase.getChars() : null);
return passphrase == null ? null :
new BcPBESecretKeyDecryptorBuilder(calculatorProvider)
.build(passphrase.getChars());
}
@Override
@Nullable
public PBESecretKeyEncryptor getEncryptor(Long keyId) throws PGPException {
Passphrase passphrase = passphraseProvider.getPassphraseFor(keyId);
return new BcPBESecretKeyEncryptorBuilder(
protectionSettings.getEncryptionAlgorithm().getAlgorithmId(),
calculatorProvider.get(protectionSettings.getHashAlgorithm().getAlgorithmId()),
protectionSettings.getS2kCount())
.build(passphrase != null ? passphrase.getChars() : null);
return passphrase == null ? null :
new BcPBESecretKeyEncryptorBuilder(
protectionSettings.getEncryptionAlgorithm().getAlgorithmId(),
calculatorProvider.get(protectionSettings.getHashAlgorithm().getAlgorithmId()),
protectionSettings.getS2kCount())
.build(passphrase.getChars());
}
}