Skip to content

Commit 2597de2

Browse files
committed
Fix checkstyle errors in various v6 related tests
1 parent 93679b1 commit 2597de2

File tree

6 files changed

+36
-46
lines changed

6 files changed

+36
-46
lines changed

pg/src/test/java/org/bouncycastle/bcpg/test/OCBEncryptedDataPacketTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@
66
import java.io.ByteArrayInputStream;
77
import java.io.IOException;
88

9-
public class OCBEncryptedDataPacketTest extends AbstractPacketTest {
9+
public class OCBEncryptedDataPacketTest
10+
extends AbstractPacketTest
11+
{
1012
@Override
11-
public String getName() {
13+
public String getName()
14+
{
1215
return "OCBEncryptedDataPacketTest";
1316
}
1417

1518
@Override
16-
public void performTest() throws Exception {
19+
public void performTest()
20+
throws Exception
21+
{
1722
parseTestVector();
1823
parseUnsupportedPacketVersion();
1924
}
2025

21-
private void parseTestVector() throws IOException {
26+
private void parseTestVector()
27+
throws IOException
28+
{
2229
String testVector = "" +
2330
"d45301090210c265ff63a61ed8af00fa" +
2431
"43866be8eb9eef77241518a3d60e387b" +
@@ -39,7 +46,9 @@ private void parseTestVector() throws IOException {
3946
isEncodingEqual("IV mismatch", Hex.decode("C265FF63A61ED8AF00FA43866BE8EB"), p.getIV());
4047
}
4148

42-
private void parseUnsupportedPacketVersion() throws IOException {
49+
private void parseUnsupportedPacketVersion()
50+
throws IOException
51+
{
4352
// Test vector with modified packet version 99
4453
String testVector = "" +
4554
"d45399090210c265ff63a61ed8af00fa" +

pg/src/test/java/org/bouncycastle/bcpg/test/OnePassSignaturePacketTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private void testParseV6OnePassSignaturePacket()
3636
issuerFp, ops.getFingerprint());
3737
isTrue("OPS packet key-ID mismatch",
3838
// key-ID are the first 8 octets of the fingerprint
39+
// -DM Hex.toHexString
3940
Hex.toHexString(issuerFp).startsWith(Long.toHexString(ops.getKeyID())));
4041
isEncodingEqual("OPS packet salt mismatch",
4142
salt, ops.getSalt());

pg/src/test/java/org/bouncycastle/bcpg/test/UnknownPublicKeyPacketTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public void performTest()
3232
parseUnknownPublicKey();
3333
}
3434

35-
private void parseUnknownPublicKey() throws ParseException, IOException {
35+
private void parseUnknownPublicKey()
36+
throws ParseException, IOException
37+
{
3638
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
3739
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
3840

pg/src/test/java/org/bouncycastle/openpgp/test/AEADProtectedPGPSecretKeyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ private void testUnlockKeyWithWrongPassphraseJca()
272272
{
273273
sk.extractPrivateKey(jceDecBuilder.build("Yang".toCharArray()));
274274
fail("Expected PGPException due to wrong passphrase");
275-
} catch (PGPException e)
275+
}
276+
catch (PGPException e)
276277
{
277278
// expected
278279
}

pg/src/test/java/org/bouncycastle/openpgp/test/PGPAeadTest.java

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
4545
import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
4646
import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
47+
import org.bouncycastle.test.DumpUtil;
4748
import org.bouncycastle.util.Arrays;
4849
import org.bouncycastle.util.Exceptions;
4950
import org.bouncycastle.util.Pack;
@@ -174,11 +175,9 @@ private void knownV5TestVectorDecryptionTests()
174175
throws IOException, PGPException
175176
{
176177
// test known-good V5 test vectors
177-
System.out.println("Test V5 BC Decryption");
178178
testBcDecryption(V5_EAX_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
179179
testBcDecryption(V5_OCB_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
180180
testBcDecryption(V5_GCM_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
181-
System.out.println("Test V5 JCA Decryption");
182181
testJceDecryption(V5_EAX_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
183182
testJceDecryption(V5_OCB_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
184183
testJceDecryption(V5_GCM_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
@@ -187,12 +186,10 @@ private void knownV5TestVectorDecryptionTests()
187186
private void knownV6TestVectorDecryptionTests()
188187
throws IOException, PGPException
189188
{
190-
// Test known-good V6 test vectors TODO: decryption tests should be working...
191-
System.out.println("Test V6 BC Decryption");
189+
// Test known-good V6 test vectors TODO: decryption tests
192190
testBcDecryption(V6_EAX_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
193191
testBcDecryption(V6_OCB_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
194192
testBcDecryption(V6_GCM_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
195-
System.out.println("Test V6 JCA Decryption");
196193
testJceDecryption(V6_EAX_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
197194
testJceDecryption(V6_OCB_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
198195
testJceDecryption(V6_GCM_PACKET_SEQUENCE, PASSWORD, PLAINTEXT);
@@ -201,36 +198,28 @@ private void knownV6TestVectorDecryptionTests()
201198
private void testBcRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
202199
throws PGPException, IOException
203200
{
204-
System.out.println("Test BC RoundTrip " + (v5AEAD ? "V5" : "V6") + " " + algNames(aeadAlg, symAlg));
205201
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
206-
System.out.println(armored);
207202
testBcDecryption(armored, password, plaintext);
208203
}
209204

210205
private void testJceRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
211206
throws PGPException, IOException
212207
{
213-
System.out.println("Test JCE RoundTrip " + (v5AEAD ? "V5" : "V6") + " " + algNames(aeadAlg, symAlg));
214208
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
215-
System.out.println(armored);
216209
testJceDecryption(armored, password, plaintext);
217210
}
218211

219212
private void testBcJceRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
220213
throws PGPException, IOException
221214
{
222-
System.out.println("Test BC encrypt, JCE decrypt " + (v5AEAD ? "V5" : "V6") + " " + algNames(aeadAlg, symAlg));
223215
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
224-
System.out.println(armored);
225216
testJceDecryption(armored, password, plaintext);
226217
}
227218

228219
private void testJceBcRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
229220
throws PGPException, IOException
230221
{
231-
System.out.println("Test JCE encrypt, BC decrypt " + (v5AEAD ? "V5" : "V6") + " " + algNames(aeadAlg, symAlg));
232222
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
233-
System.out.println(armored);
234223
testBcDecryption(armored, password, plaintext);
235224
}
236225

@@ -365,7 +354,9 @@ private void testBcDecryption(String armoredMessage, char[] password, byte[] exp
365354

366355
if (o != null)
367356
{
357+
// -DM System.out.println
368358
System.out.println("Unexpected trailing packet.");
359+
// -DM System.out.println
369360
System.out.println(o);
370361
}
371362
}
@@ -421,7 +412,9 @@ private void testJceDecryption(String armoredMessage, char[] password, byte[] ex
421412

422413
if (o != null)
423414
{
415+
// -DM System.out.println
424416
System.out.println("Unexpected trailing packet.");
417+
// -DM System.out.println
425418
System.out.println(o);
426419
}
427420
}
@@ -435,30 +428,8 @@ private void testJceDecryption(String armoredMessage, char[] password, byte[] ex
435428

436429
public static void printHex(byte[] bytes)
437430
{
438-
boolean separate = true;
439-
boolean prefix = true;
440-
String hex = Hex.toHexString(bytes);
441-
StringBuffer sb = new StringBuffer();
442-
for (int i = 0; i < hex.length() / 2; i++)
443-
{
444-
if (prefix && i % 8 == 0)
445-
{
446-
sb.append("0x").append(Hex.toHexString(Pack.intToBigEndian(i & 0xFFFFF))).append(" ");
447-
}
448-
sb.append(hex.substring(i * 2, i * 2 + 2));
449-
if (separate)
450-
{
451-
if ((i + 1) % 8 == 0)
452-
{
453-
sb.append('\n');
454-
}
455-
else
456-
{
457-
sb.append(' ');
458-
}
459-
}
460-
}
461-
System.out.println(sb);
431+
// -DM System.out.println
432+
System.out.println(DumpUtil.hexdump(bytes));
462433
}
463434

464435
private static String algNames(int aeadAlg, int symAlg)

pg/src/test/java/org/bouncycastle/openpgp/test/PGPv6SignatureTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ private void verifySignaturesOnKey(String armoredKey)
411411
}
412412
else
413413
{
414+
// -DM System.out.println
414415
System.out.println("Did not find signing key for DK sig");
415416
}
416417
}
@@ -432,6 +433,7 @@ private void verifySignaturesOnKey(String armoredKey)
432433
}
433434
else
434435
{
436+
// -DM System.out.println
435437
System.out.println("Did not find signing key for UID sig for " + uid);
436438
}
437439
}
@@ -453,6 +455,8 @@ private void verifySignaturesOnKey(String armoredKey)
453455
}
454456
else
455457
{
458+
// -DM System.out.println
459+
// -DM Hex.toHexString
456460
System.out.println("Did not find singing key for subkey " + Hex.toHexString(subkey.getFingerprint()) + " binding signature");
457461
}
458462
}
@@ -473,15 +477,17 @@ private PGPPublicKey getSigningKeyFor(PGPKeyRing keys, PGPSignature sig)
473477
for (SignatureSubpacket p : sig.getHashedSubPackets().getSubpackets(SignatureSubpacketTags.ISSUER_FINGERPRINT))
474478
{
475479
IssuerFingerprint fp = (IssuerFingerprint) p;
476-
if (Arrays.areEqual(k.getFingerprint(), fp.getFingerprint())) {
480+
if (Arrays.areEqual(k.getFingerprint(), fp.getFingerprint()))
481+
{
477482
return k;
478483
}
479484
}
480485

481486
for (SignatureSubpacket p : sig.getUnhashedSubPackets().getSubpackets(SignatureSubpacketTags.ISSUER_FINGERPRINT))
482487
{
483488
IssuerFingerprint fp = (IssuerFingerprint) p;
484-
if (Arrays.areEqual(k.getFingerprint(), fp.getFingerprint())) {
489+
if (Arrays.areEqual(k.getFingerprint(), fp.getFingerprint()))
490+
{
485491
return k;
486492
}
487493
}

0 commit comments

Comments
 (0)