mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-13 12:19:38 +02:00
Incorporate feedback from @IvanPizhenko. Thanks!
This commit is contained in:
parent
64cc9ecca4
commit
ec85f53bb6
21 changed files with 137 additions and 101 deletions
|
@ -17,16 +17,9 @@ package org.junit;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JUtils {
|
||||
|
||||
public static void assertEquals(long a, long b, long delta) {
|
||||
assertTrue(a - delta <= b && a + delta >= b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparatorLearningTest() {
|
||||
assertEquals(-1, Integer.compare(5,6), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.util.BCUtil;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.util.BCUtil;
|
||||
|
||||
public class KeyRevocationTest {
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.util.BCUtil;
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@
|
|||
*/
|
||||
package org.pgpainless.util.selection.signature;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
|
@ -29,7 +32,7 @@ import org.pgpainless.signature.SelectSignatureFromKey;
|
|||
public class SelectSignatureFromKeyTest {
|
||||
|
||||
@Test
|
||||
public void validKeyTest() throws IOException, PGPException {
|
||||
public void validKeyTest() throws IOException {
|
||||
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"\n" +
|
||||
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
|
||||
|
@ -90,19 +93,19 @@ public class SelectSignatureFromKeyTest {
|
|||
PGPPublicKey primaryKey = publicKeys.getPublicKey();
|
||||
while (keyIt.hasNext()) {
|
||||
PGPPublicKey publicKey = keyIt.next();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(publicKey.getKeyID());
|
||||
// CHECKSTYLE:ON
|
||||
if (publicKey == primaryKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean validBinding = false;
|
||||
Iterator<PGPSignature> signatures = publicKey.getSignatures();
|
||||
while (signatures.hasNext()) {
|
||||
PGPSignature signature = signatures.next();
|
||||
if (SelectSignatureFromKey.isValidSubkeyBindingSignature(primaryKey, publicKey).accept(signature, publicKey, publicKeys)) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Valid subkey binding signature");
|
||||
// CHECKSTYLE:ON
|
||||
validBinding = true;
|
||||
}
|
||||
}
|
||||
assertTrue(validBinding);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,31 +159,17 @@ public class SelectSignatureFromKeyTest {
|
|||
PGPPublicKey primaryKey = publicKeys.getPublicKey();
|
||||
while (keyIt.hasNext()) {
|
||||
PGPPublicKey publicKey = keyIt.next();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(publicKey.getKeyID());
|
||||
// CHECKSTYLE:ON
|
||||
if (publicKey.isMasterKey()) {
|
||||
Iterator<PGPSignature> signatures = publicKey.getSignatures();
|
||||
boolean isValidPrimaryKey = false;
|
||||
boolean isRevokedPrimaryKey = false;
|
||||
while (signatures.hasNext()) {
|
||||
PGPSignature signature = signatures.next();
|
||||
}
|
||||
} else {
|
||||
Iterator<PGPSignature> signatures = publicKey.getSignatures();
|
||||
while (signatures.hasNext()) {
|
||||
PGPSignature signature = signatures.next();
|
||||
|
||||
if (SelectSignatureFromKey.isValidSubkeyBindingSignature(primaryKey, publicKey).accept(signature, publicKey, publicKeys)) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Valid subkey binding signature");
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
}
|
||||
if (publicKey == primaryKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Iterator<PGPSignature> signatures = publicKey.getSignatures();
|
||||
while (signatures.hasNext()) {
|
||||
PGPSignature signature = signatures.next();
|
||||
if (SelectSignatureFromKey.isValidSubkeyBindingSignature(primaryKey, publicKey).accept(signature, publicKey, publicKeys)) {
|
||||
fail("Implementation MUST NOT accept this subkey as bound valid since the backsig is missing.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue