mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
SOP: Allow generation of keys without user-ids
This commit is contained in:
parent
19e484b552
commit
b6724d485c
3 changed files with 32 additions and 37 deletions
|
@ -28,7 +28,7 @@ public class GenerateKeyImpl implements GenerateKey {
|
|||
|
||||
private boolean armor = true;
|
||||
private final Set<String> userIds = new LinkedHashSet<>();
|
||||
private Passphrase passphrase;
|
||||
private Passphrase passphrase = Passphrase.emptyPassphrase();
|
||||
|
||||
@Override
|
||||
public GenerateKey noArmor() {
|
||||
|
@ -51,15 +51,12 @@ public class GenerateKeyImpl implements GenerateKey {
|
|||
@Override
|
||||
public Ready generate() throws SOPGPException.MissingArg, SOPGPException.UnsupportedAsymmetricAlgo {
|
||||
Iterator<String> userIdIterator = userIds.iterator();
|
||||
if (!userIdIterator.hasNext()) {
|
||||
throw new SOPGPException.MissingArg("Missing user-id.");
|
||||
}
|
||||
|
||||
Passphrase passphraseCopy = new Passphrase(passphrase.getChars()); // generateKeyRing clears the original passphrase
|
||||
PGPSecretKeyRing key;
|
||||
try {
|
||||
String primaryUserId = userIdIterator.hasNext() ? userIdIterator.next() : null;
|
||||
key = PGPainless.generateKeyRing()
|
||||
.modernKeyRing(userIdIterator.next(), passphrase);
|
||||
.modernKeyRing(primaryUserId, passphrase);
|
||||
|
||||
if (userIdIterator.hasNext()) {
|
||||
SecretKeyRingEditorInterface editor = PGPainless.modifyKeyRing(key);
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.pgpainless.sop;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,7 +21,6 @@ import org.pgpainless.key.info.KeyRingInfo;
|
|||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
public class GenerateKeyTest {
|
||||
|
||||
|
@ -33,11 +31,6 @@ public class GenerateKeyTest {
|
|||
sop = new SOPImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingUserId() {
|
||||
assertThrows(SOPGPException.MissingArg.class, () -> sop.generateKey().generate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKey() throws IOException {
|
||||
byte[] bytes = sop.generateKey()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue