Skip to content

Commit d6ba657

Browse files
committed
java 4 updates
1 parent c2714b0 commit d6ba657

File tree

11 files changed

+53
-33
lines changed

11 files changed

+53
-33
lines changed

core/src/test/java/org/bouncycastle/pqc/crypto/test/AllTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ public void testPQC()
7676
}
7777
}
7878

79-
static boolean parseBoolean(String value)
80-
{
81-
return "true".equalsIgnoreCase(value);
82-
}
83-
8479
static class BCTestSetup
8580
extends TestSetup
8681
{

core/src/test/java/org/bouncycastle/pqc/crypto/test/CrystalsDilithiumTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public void testSigVer() throws IOException
216216
{
217217
if (buf.size() > 0)
218218
{
219-
boolean testPassed = Boolean.parseBoolean((String)buf.get("testPassed"));
219+
boolean testPassed = TestUtils.parseBoolean((String)buf.get("testPassed"));
220220
String reason = (String)buf.get("reason");
221221
byte[] pk = Hex.decode((String)buf.get("pk"));
222222
byte[] sk = Hex.decode((String)buf.get("sk"));

core/src/test/java/org/bouncycastle/pqc/crypto/test/MLDSATest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public void testConsistency() throws Exception
5151

5252
MLDSAKeyPairGenerator kpg = new MLDSAKeyPairGenerator();
5353

54-
for (MLDSAParameters parameters : PARAMETER_SETS)
54+
for (int idx = 0; idx != PARAMETER_SETS.length; idx++)
5555
{
56+
MLDSAParameters parameters = PARAMETER_SETS[idx];
5657
kpg.init(new MLDSAKeyGenerationParameters(random, parameters));
5758

5859
int msgSize = 0;
@@ -250,7 +251,7 @@ public void testSigVer()
250251
{
251252
if (buf.size() > 0)
252253
{
253-
boolean testPassed = AllTests.parseBoolean((String)buf.get("testPassed"));
254+
boolean testPassed = TestUtils.parseBoolean((String)buf.get("testPassed"));
254255
String reason = (String)buf.get("reason");
255256
byte[] pk = Hex.decode((String)buf.get("pk"));
256257
byte[] message = Hex.decode((String)buf.get("message"));
@@ -321,7 +322,7 @@ public void testKeyGenCombinedVectorSet()
321322
byte[] sk = Hex.decode((String)buf.get("sk"));
322323

323324
FixedSecureRandom random = new FixedSecureRandom(seed);
324-
MLDSAParameters parameters = (MLSDAParameters)PARAMETERS_MAP.get((String)buf.get("parameterSet"));
325+
MLDSAParameters parameters = (MLDSAParameters)PARAMETERS_MAP.get((String)buf.get("parameterSet"));
325326

326327
MLDSAKeyPairGenerator kpGen = new MLDSAKeyPairGenerator();
327328
kpGen.init(new MLDSAKeyGenerationParameters(random, parameters));
@@ -372,7 +373,7 @@ public void testSigGenCombinedVectorSet()
372373
{
373374
if (buf.size() > 0)
374375
{
375-
boolean deterministic = Boolean.valueOf((String)buf.get("deterministic"));
376+
boolean deterministic = TestUtils.parseBoolean((String)buf.get("deterministic"));
376377
byte[] sk = Hex.decode((String)buf.get("sk"));
377378
byte[] message = Hex.decode((String)buf.get("message"));
378379
byte[] signature = Hex.decode((String)buf.get("signature"));
@@ -386,8 +387,7 @@ public void testSigGenCombinedVectorSet()
386387
rnd = new byte[32];
387388
}
388389

389-
MLDSAParameters parameters = parametersMap.get((String)buf.get("parameterSet"));
390-
390+
MLDSAParameters parameters = (MLDSAParameters)PARAMETERS_MAP.get((String)buf.get("parameterSet"));
391391
MLDSAPrivateKeyParameters privParams = new MLDSAPrivateKeyParameters(parameters, sk, null);
392392

393393
// sign
@@ -433,7 +433,7 @@ public void testSigVerCombinedVectorSet()
433433
{
434434
if (!buf.isEmpty())
435435
{
436-
boolean expectedResult = AllTests.parseBoolean((String)buf.get("testPassed"));
436+
boolean expectedResult = TestUtils.parseBoolean((String)buf.get("testPassed"));
437437

438438
byte[] pk = Hex.decode((String)buf.get("pk"));
439439
byte[] message = Hex.decode((String)buf.get("message"));

core/src/test/java/org/bouncycastle/pqc/crypto/test/SLHDSATest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public void testConsistency()
6969

7070
SLHDSAKeyPairGenerator kpg = new SLHDSAKeyPairGenerator();
7171

72-
for (SLHDSAParameters parameters : PARAMETER_SETS)
72+
for (int idx = 0; idx != PARAMETER_SETS.length; idx++)
7373
{
74+
SLHDSAParameters parameters = PARAMETER_SETS[idx];
7475
kpg.init(new SLHDSAKeyGenerationParameters(random, parameters));
7576

7677
{
@@ -234,7 +235,7 @@ public void testSigVerSingleFile() throws IOException
234235
{
235236
if (buf.size() > 0)
236237
{
237-
boolean testPassed = AllTests.parseBoolean((String)buf.get("testPassed"));
238+
boolean testPassed = TestUtils.parseBoolean((String)buf.get("testPassed"));
238239
// boolean deterministic = !buf.containsKey("additionalRandomness");
239240
String reason = (String)buf.get("reason");
240241

@@ -461,7 +462,7 @@ public void testSigVer() throws IOException
461462
{
462463
if (buf.size() > 0)
463464
{
464-
boolean testPassed = AllTests.parseBoolean((String)buf.get("testPassed"));
465+
boolean testPassed = TestUtils.parseBoolean((String)buf.get("testPassed"));
465466
// boolean deterministic = !buf.containsKey("additionalRandomness");
466467
String reason = (String)buf.get("reason");
467468

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.bouncycastle.pqc.crypto.test;
2+
3+
class TestUtils
4+
{
5+
static boolean parseBoolean(String value)
6+
{
7+
return "true".equalsIgnoreCase(value);
8+
}
9+
}

core/src/test/java/org/bouncycastle/util/io/pem/test/AllTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void testRegularBlobEndLaxParsing()
141141
}
142142
else
143143
{
144-
System.clearProperty(PemReader.LAX_PEM_PARSING_SYSTEM_PROPERTY_NAME);
144+
System.setProperty(PemReader.LAX_PEM_PARSING_SYSTEM_PROPERTY_NAME, "");
145145
}
146146
}
147147

pg/src/main/java/org/bouncycastle/bcpg/KeyIdentifier.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bouncycastle.bcpg;
22

3+
import java.util.Iterator;
34
import java.util.List;
45

56
import org.bouncycastle.util.Arrays;
@@ -166,9 +167,9 @@ public boolean matches(KeyIdentifier other)
166167
*/
167168
public boolean isPresentIn(List<KeyIdentifier> others)
168169
{
169-
for (KeyIdentifier other: others)
170+
for (Iterator it = others.iterator(); it.hasNext();)
170171
{
171-
if (this.matches(other))
172+
if (this.matches((KeyIdentifier)it.next()))
172173
{
173174
return true;
174175
}

pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,9 @@ private void setIssuerKeyId()
745745
return;
746746
}
747747

748-
for (SignatureSubpacket p : hashedData)
748+
for (int idx = 0; idx != hashedData.length; idx++)
749749
{
750+
SignatureSubpacket p = hashedData[idx];
750751
if (p instanceof IssuerKeyID)
751752
{
752753
keyID = ((IssuerKeyID) p).getKeyID();
@@ -759,8 +760,9 @@ private void setIssuerKeyId()
759760
}
760761
}
761762

762-
for (SignatureSubpacket p : unhashedData)
763+
for (int idx = 0; idx != unhashedData.length; idx++)
763764
{
765+
SignatureSubpacket p = unhashedData[idx];
764766
if (p instanceof IssuerKeyID)
765767
{
766768
keyID = ((IssuerKeyID) p).getKeyID();

pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyRing.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ public PGPPublicKey getPublicKey(byte[] fingerprint)
198198
@Override
199199
public PGPPublicKey getPublicKey(KeyIdentifier identifier)
200200
{
201-
for (PGPPublicKey k : keys)
201+
for (Iterator it = keys.iterator(); it.hasNext();)
202202
{
203+
PGPPublicKey k = (PGPPublicKey)it.next();
203204
if (identifier.matches(k.getKeyIdentifier()))
204205
{
205206
return k;
@@ -212,8 +213,9 @@ public PGPPublicKey getPublicKey(KeyIdentifier identifier)
212213
public Iterator<PGPPublicKey> getPublicKeys(KeyIdentifier identifier)
213214
{
214215
List<PGPPublicKey> matches = new ArrayList<PGPPublicKey>();
215-
for (PGPPublicKey k : keys)
216+
for (Iterator it = keys.iterator(); it.hasNext();)
216217
{
218+
PGPPublicKey k = (PGPPublicKey)it.next();
217219
if (identifier.matches(k.getKeyIdentifier()))
218220
{
219221
matches.add(k);
@@ -251,8 +253,9 @@ public Iterator<PGPPublicKey> getKeysWithSignaturesBy(long keyID)
251253
public Iterator<PGPPublicKey> getKeysWithSignaturesBy(KeyIdentifier identifier)
252254
{
253255
List<PGPPublicKey> keysWithSigs = new ArrayList<PGPPublicKey>();
254-
for (PGPPublicKey k : keys)
256+
for (Iterator it = keys.iterator(); it.hasNext();)
255257
{
258+
PGPPublicKey k = (PGPPublicKey)it.next();
256259
Iterator<PGPSignature> sigIt = k.getSignaturesForKey(identifier);
257260
if (sigIt.hasNext())
258261
{

pg/src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,18 @@ public PGPPublicKey getPublicKey(byte[] fingerprint)
260260
@Override
261261
public PGPPublicKey getPublicKey(KeyIdentifier identifier)
262262
{
263-
for (PGPSecretKey k : keys)
263+
for (Iterator it = keys.iterator(); it.hasNext();)
264264
{
265+
PGPSecretKey k = (PGPSecretKey)it.next();
265266
if (k.getPublicKey() != null && identifier.matches(k.getKeyIdentifier()))
266267
{
267268
return k.getPublicKey();
268269
}
269270
}
270271

271-
for (PGPPublicKey k : extraPubKeys)
272+
for (Iterator it = extraPubKeys.iterator(); it.hasNext();)
272273
{
274+
PGPPublicKey k = (PGPPublicKey)it.next();
273275
if (identifier.matches(k.getKeyIdentifier()))
274276
{
275277
return k;
@@ -282,16 +284,18 @@ public PGPPublicKey getPublicKey(KeyIdentifier identifier)
282284
public Iterator<PGPPublicKey> getPublicKeys(KeyIdentifier identifier)
283285
{
284286
List<PGPPublicKey> matches = new ArrayList<PGPPublicKey>();
285-
for (PGPSecretKey k : keys)
287+
for (Iterator it = keys.iterator(); it.hasNext();)
286288
{
289+
PGPSecretKey k = (PGPSecretKey)it.next();
287290
if (k.getPublicKey() != null && identifier.matches(k.getKeyIdentifier()))
288291
{
289292
matches.add(k.getPublicKey());
290293
}
291294
}
292295

293-
for (PGPPublicKey k : extraPubKeys)
296+
for (Iterator it = extraPubKeys.iterator(); it.hasNext();)
294297
{
298+
PGPPublicKey k = (PGPPublicKey)it.next();
295299
if (identifier.matches(k.getKeyIdentifier()))
296300
{
297301
matches.add(k);
@@ -302,8 +306,9 @@ public Iterator<PGPPublicKey> getPublicKeys(KeyIdentifier identifier)
302306

303307
public PGPSecretKey getSecretKey(KeyIdentifier identifier)
304308
{
305-
for (PGPSecretKey k : keys)
309+
for (Iterator it = keys.iterator(); it.hasNext();)
306310
{
311+
PGPSecretKey k = (PGPSecretKey)it.next();
307312
if (identifier.matches(k.getKeyIdentifier()))
308313
{
309314
return k;
@@ -315,8 +320,9 @@ public PGPSecretKey getSecretKey(KeyIdentifier identifier)
315320
public Iterator<PGPSecretKey> getSecretKeys(KeyIdentifier identifier)
316321
{
317322
List<PGPSecretKey> matches = new ArrayList<PGPSecretKey>();
318-
for (PGPSecretKey k : keys)
323+
for (Iterator it = keys.iterator(); it.hasNext();)
319324
{
325+
PGPSecretKey k = (PGPSecretKey)it.next();
320326
if (identifier.matches(k.getKeyIdentifier()))
321327
{
322328
matches.add(k);
@@ -354,8 +360,9 @@ public Iterator<PGPPublicKey> getKeysWithSignaturesBy(long keyID)
354360
public Iterator<PGPPublicKey> getKeysWithSignaturesBy(KeyIdentifier identifier)
355361
{
356362
List<PGPPublicKey> keysWithSigs = new ArrayList<PGPPublicKey>();
357-
for (PGPSecretKey k : keys)
363+
for (Iterator it = keys.iterator(); it.hasNext();)
358364
{
365+
PGPSecretKey k = (PGPSecretKey)it.next();
359366
if (k.getPublicKey() == null)
360367
{
361368
continue;
@@ -366,8 +373,9 @@ public Iterator<PGPPublicKey> getKeysWithSignaturesBy(KeyIdentifier identifier)
366373
keysWithSigs.add(k.getPublicKey());
367374
}
368375
}
369-
for (PGPPublicKey k : extraPubKeys)
376+
for (Iterator it = extraPubKeys.iterator(); it.hasNext();)
370377
{
378+
PGPPublicKey k = (PGPPublicKey)it.next;
371379
Iterator<PGPSignature> sigIt = k.getSignaturesForKey(identifier);
372380
if (sigIt.hasNext())
373381
{

0 commit comments

Comments
 (0)