1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 14:22:05 +01:00

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

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);
}
}