1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-10 02:39:39 +02:00

SOP: Allow generation of keys without user-ids

This commit is contained in:
Paul Schaub 2022-12-13 17:02:53 +01:00
parent 66abd5f65f
commit 2d46fb18f7
3 changed files with 32 additions and 37 deletions

View file

@ -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,14 +51,11 @@ 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.");
}
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);

View file

@ -6,7 +6,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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@ -17,7 +16,6 @@ import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.key.info.KeyRingInfo;
import sop.SOP;
import sop.exception.SOPGPException;
public class GenerateKeyTest {
@ -28,11 +26,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()