mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 22:32:07 +01:00
Add static factory methods for SecretKeyRingProtector implementations
This commit is contained in:
parent
935af80d14
commit
3173ddbc45
1 changed files with 19 additions and 0 deletions
|
@ -15,11 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package org.pgpainless.key.protection;
|
package org.pgpainless.key.protection;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
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.PBESecretKeyDecryptor;
|
||||||
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
|
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
|
||||||
|
import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public interface SecretKeyRingProtector {
|
public interface SecretKeyRingProtector {
|
||||||
|
|
||||||
|
@ -42,4 +46,19 @@ public interface SecretKeyRingProtector {
|
||||||
*/
|
*/
|
||||||
@Nullable PBESecretKeyEncryptor getEncryptor(Long keyId) throws PGPException;
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue