Add static factory methods for SecretKeyRingProtector implementations

This commit is contained in:
Paul Schaub 2020-11-29 19:08:52 +01:00
parent 935af80d14
commit 3173ddbc45
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 19 additions and 0 deletions

View File

@ -15,11 +15,15 @@
*/
package org.pgpainless.key.protection;
import java.util.Map;
import javax.annotation.Nullable;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
import org.pgpainless.util.Passphrase;
public interface SecretKeyRingProtector {
@ -42,4 +46,19 @@ public interface SecretKeyRingProtector {
*/
@Nullable PBESecretKeyEncryptor getEncryptor(Long keyId) throws PGPException;
static SecretKeyRingProtector unlockAllKeysWith(Passphrase passphrase, PGPSecretKeyRing keys) {
return PasswordBasedSecretKeyRingProtector.forKey(keys, passphrase);
}
static SecretKeyRingProtector unlockSingleKeyWith(Passphrase passphrase, PGPSecretKey key) {
return PasswordBasedSecretKeyRingProtector.forKey(key, passphrase);
}
static SecretKeyRingProtector unprotectedKeys() {
return new UnprotectedKeysProtector();
}
static SecretKeyRingProtector fromPassphraseMap(Map<Long, Passphrase> passphraseMap) {
return new PassphraseMapKeyRingProtector(passphraseMap, KeyRingProtectionSettings.secureDefaultSettings(), null);
}
}