Skip to content

Commit

Permalink
Add static factory methods for SecretKeyRingProtector implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Nov 29, 2020
1 parent 935af80 commit 3173ddb
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}
}

0 comments on commit 3173ddb

Please sign in to comment.