Skip to content

Commit 800e5f1

Browse files
committed
Java 5 updates.
1 parent 2421ab9 commit 800e5f1

13 files changed

+79
-56
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public Builder addSplitMultilineComment(String comment)
639639
line = line.substring(availableCommentCharsPerLine).trim();
640640
}
641641

642-
if (!line.isEmpty())
642+
if (line.length() != 0)
643643
{
644644
addComment(line);
645645
}

pg/src/main/java/org/bouncycastle/openpgp/api/AbstractOpenPGPDocumentSignatureGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.Date;
66
import java.util.Iterator;
77
import java.util.List;
8-
import java.util.Objects;
98
import java.util.function.IntPredicate;
109

1110
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
@@ -64,7 +63,11 @@ public AbstractOpenPGPDocumentSignatureGenerator(OpenPGPImplementation implement
6463
*/
6564
public T setSigningKeySelector(SubkeySelector signingKeySelector)
6665
{
67-
this.signingKeySelector = Objects.requireNonNull(signingKeySelector);
66+
if (signingKeySelector == null)
67+
{
68+
throw new NullPointerException();
69+
}
70+
this.signingKeySelector = signingKeySelector;
6871
return (T)this;
6972
}
7073

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKeyEditor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public OpenPGPKeyEditor addUserId(String userId,
101101
SignatureParameters.Callback signatureCallback)
102102
throws PGPException
103103
{
104-
if (userId == null || userId.trim().isEmpty())
104+
// care needs to run with Java 5
105+
if (userId == null || userId.trim().length() == 0)
105106
{
106107
throw new IllegalArgumentException("User-ID cannot be null or empty.");
107108
}

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKeyGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ public WithPrimaryKey addUserId(
379379
SignatureParameters.Callback signatureParameters)
380380
throws PGPException
381381
{
382-
if (userId == null || userId.trim().isEmpty())
382+
// care - needs to run with Java 5.
383+
if (userId == null || userId.trim().length() == 0)
383384
{
384385
throw new IllegalArgumentException("User-ID cannot be null or empty.");
385386
}

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKeyMaterialPool.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.Iterator;
66
import java.util.Map;
7-
import java.util.Objects;
87
import java.util.stream.Collectors;
98
import java.util.stream.Stream;
109

@@ -63,7 +62,11 @@ public OpenPGPKeyMaterialPool(Collection<M> items)
6362
*/
6463
public OpenPGPKeyMaterialPool<M> setMissingItemCallback(OpenPGPKeyMaterialProvider<M> callback)
6564
{
66-
this.callback = Objects.requireNonNull(callback);
65+
if (callback == null)
66+
{
67+
throw new NullPointerException();
68+
}
69+
this.callback = callback;
6770
return this;
6871
}
6972

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPMessageGenerator.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.HashSet;
99
import java.util.Iterator;
1010
import java.util.List;
11-
import java.util.Objects;
1211
import java.util.Set;
1312

1413
import org.bouncycastle.bcpg.AEADAlgorithmTags;
@@ -571,7 +570,11 @@ public int negotiateCompression(OpenPGPMessageGenerator configuration, OpenPGPPo
571570
*/
572571
public OpenPGPMessageGenerator setPasswordBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pbeNegotiator)
573572
{
574-
this.passwordBasedEncryptionNegotiator = Objects.requireNonNull(pbeNegotiator);
573+
if (pbeNegotiator == null)
574+
{
575+
throw new NullPointerException();
576+
}
577+
this.passwordBasedEncryptionNegotiator = pbeNegotiator;
575578
return this;
576579
}
577580

@@ -584,7 +587,11 @@ public OpenPGPMessageGenerator setPasswordBasedEncryptionNegotiator(OpenPGPEncry
584587
*/
585588
public OpenPGPMessageGenerator setPublicKeyBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pkbeNegotiator)
586589
{
587-
this.publicKeyBasedEncryptionNegotiator = Objects.requireNonNull(pkbeNegotiator);
590+
if (pkbeNegotiator == null)
591+
{
592+
throw new NullPointerException();
593+
}
594+
this.publicKeyBasedEncryptionNegotiator = pkbeNegotiator;
588595
return this;
589596
}
590597

@@ -598,7 +605,11 @@ public OpenPGPMessageGenerator setPublicKeyBasedEncryptionNegotiator(OpenPGPEncr
598605
*/
599606
public OpenPGPMessageGenerator setEncryptionKeySelector(SubkeySelector encryptionKeySelector)
600607
{
601-
this.encryptionKeySelector = Objects.requireNonNull(encryptionKeySelector);
608+
if (encryptionKeySelector == null)
609+
{
610+
throw new NullPointerException();
611+
}
612+
this.encryptionKeySelector = encryptionKeySelector;
602613
return this;
603614
}
604615

@@ -612,7 +623,11 @@ public OpenPGPMessageGenerator setEncryptionKeySelector(SubkeySelector encryptio
612623
*/
613624
public OpenPGPMessageGenerator setCompressionNegotiator(CompressionNegotiator compressionNegotiator)
614625
{
615-
this.compressionNegotiator = Objects.requireNonNull(compressionNegotiator);
626+
if (compressionNegotiator == null)
627+
{
628+
throw new NullPointerException();
629+
}
630+
this.compressionNegotiator = compressionNegotiator;
616631
return this;
617632
}
618633

@@ -624,7 +639,11 @@ public OpenPGPMessageGenerator setCompressionNegotiator(CompressionNegotiator co
624639
*/
625640
public OpenPGPMessageGenerator setArmorStreamFactory(ArmoredOutputStreamFactory factory)
626641
{
627-
this.armorStreamFactory = Objects.requireNonNull(factory);
642+
if (factory == null)
643+
{
644+
throw new NullPointerException();
645+
}
646+
this.armorStreamFactory = factory;
628647
return this;
629648
}
630649

pg/src/main/java/org/bouncycastle/openpgp/api/SignatureParameters.java

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

33
import java.util.Date;
4-
import java.util.Objects;
54

65
import org.bouncycastle.openpgp.PGPSignature;
76
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
@@ -200,8 +199,13 @@ public int getSignatureType()
200199
*/
201200
public SignatureParameters setSignatureCreationTime(Date signatureCreationTime)
202201
{
203-
this.signatureCreationTime = Objects.requireNonNull(signatureCreationTime,
204-
"Signature creation time cannot be null.");
202+
if (signatureCreationTime == null)
203+
{
204+
throw new NullPointerException("Signature creation time cannot be null.");
205+
}
206+
207+
this.signatureCreationTime = signatureCreationTime;
208+
205209
return this;
206210
}
207211

pg/src/main/jdk1.5/org/bouncycastle/openpgp/api/SignatureParameters.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.bouncycastle.util.Arrays;
66

77
import java.util.Date;
8-
import java.util.Objects;
98

109
/**
1110
* Parameters for signature generation.
@@ -200,8 +199,11 @@ public int getSignatureType()
200199
*/
201200
public SignatureParameters setSignatureCreationTime(Date signatureCreationTime)
202201
{
203-
this.signatureCreationTime = Objects.requireNonNull(signatureCreationTime,
204-
"Signature creation time cannot be null.");
202+
if (signatureCreationTime == null)
203+
{
204+
throw new NullPointerException("Signature creation time cannot be null.");
205+
}
206+
this.signatureCreationTime = signatureCreationTime;
205207
return this;
206208
}
207209

pg/src/test/java/org/bouncycastle/openpgp/api/test/ChangeKeyPassphraseTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ public class ChangeKeyPassphraseTest
1515
protected void performTestWith(OpenPGPApi api)
1616
throws PGPException, IOException
1717
{
18-
removeAEADPassphrase(api);
19-
addAEADPassphrase(api);
20-
changeAEADPassphrase(api);
21-
22-
testChangingCFBPassphrase(api);
18+
if (System.getProperty("java.version").indexOf("1.5.") < 0)
19+
{
20+
removeAEADPassphrase(api);
21+
addAEADPassphrase(api);
22+
changeAEADPassphrase(api);
23+
24+
testChangingCFBPassphrase(api);
25+
}
2326
}
2427

2528
private void removeAEADPassphrase(OpenPGPApi api)

pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPCertificateTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.ByteArrayInputStream;
44
import java.io.IOException;
5-
import java.nio.charset.StandardCharsets;
65
import java.util.Date;
76
import java.util.List;
87

@@ -26,6 +25,7 @@
2625
import org.bouncycastle.openpgp.api.SignatureSubpacketsFunction;
2726
import org.bouncycastle.openpgp.api.util.UTCUtil;
2827
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
28+
import org.bouncycastle.util.Strings;
2929

3030
public class OpenPGPCertificateTest
3131
extends APITest
@@ -808,7 +808,6 @@ private void testGetPrimaryUserId(OpenPGPApi api)
808808
.addUserId("New primary <[email protected]>",
809809
SignatureParameters.Callback.Util.modifyHashedSubpackets(new SignatureSubpacketsFunction()
810810
{
811-
@Override
812811
public PGPSignatureSubpacketGenerator apply(PGPSignatureSubpacketGenerator subpackets)
813812
{
814813
subpackets.removePacketsOfType(SignatureSubpacketTags.CREATION_TIME);
@@ -850,7 +849,7 @@ public TestSignature(String armoredSignature, boolean expectValid, String msg)
850849
private static PGPSignature parseSignature(String armoredSignature)
851850
throws IOException
852851
{
853-
ByteArrayInputStream bIn = new ByteArrayInputStream(armoredSignature.getBytes(StandardCharsets.UTF_8));
852+
ByteArrayInputStream bIn = new ByteArrayInputStream(Strings.toUTF8ByteArray(armoredSignature));
854853
ArmoredInputStream aIn = new ArmoredInputStream(bIn);
855854
BCPGInputStream pIn = new BCPGInputStream(aIn);
856855
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);

0 commit comments

Comments
 (0)