Skip to content

Commit 70c767a

Browse files
author
gefeili
committed
Refactor of OpenPGPCertificate.getSince
1 parent b2d7832 commit 70c767a

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

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

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.Map;
1616
import java.util.Set;
1717
import java.util.TreeSet;
18-
import java.util.function.Function;
1918

2019
import org.bouncycastle.bcpg.ArmoredOutputStream;
2120
import org.bouncycastle.bcpg.BCPGInputStream;
@@ -3034,41 +3033,56 @@ public boolean isHardRevocation()
30343033
*/
30353034
public Date getSince()
30363035
{
3037-
// Find most recent chain link
3038-
// return chainLinks.stream()
3039-
// .map(it -> it.signature)
3040-
// .max(Comparator.comparing(OpenPGPComponentSignature::getCreationTime))
3041-
// .map(OpenPGPComponentSignature::getCreationTime)
3042-
// .orElse(null);
3043-
return chainLinks.stream()
3044-
.map(new Function<Link, Object>()
3045-
{
3046-
@Override
3047-
public OpenPGPComponentSignature apply(Link it)
3048-
{
3049-
return it.signature; // Replace lambda: `it -> it.signature`
3050-
}
3051-
3052-
})
3053-
.max(new Comparator<Object>()
3054-
{
3055-
@Override
3056-
public int compare(Object o1, Object o2)
3057-
{
3058-
// Replace method reference: `Comparator.comparing(OpenPGPComponentSignature::getCreationTime)`
3059-
return ((OpenPGPComponentSignature)o1).getCreationTime().compareTo(((OpenPGPComponentSignature)o2).getCreationTime());
3060-
}
3061-
})
3062-
.map(new Function<Object, Date>()
3036+
Date latestDate = null;
3037+
for (Iterator it = chainLinks.iterator(); it.hasNext(); )
3038+
{
3039+
Link link = (Link)it.next();
3040+
OpenPGPComponentSignature signature = link.getSignature();
3041+
Date currentDate = signature.getCreationTime();
3042+
if (latestDate == null || currentDate.after(latestDate))
30633043
{
3064-
@Override
3065-
public Date apply(Object sig)
3066-
{
3067-
return ((OpenPGPComponentSignature)sig).getCreationTime(); // Replace method reference: `OpenPGPComponentSignature::getCreationTime`
3068-
}
3069-
})
3070-
.orElse(null);
3044+
latestDate = currentDate;
3045+
}
3046+
}
3047+
return latestDate;
30713048
}
3049+
// public Date getSince()
3050+
// {
3051+
// // Find most recent chain link
3052+
//// return chainLinks.stream()
3053+
//// .map(it -> it.signature)
3054+
//// .max(Comparator.comparing(OpenPGPComponentSignature::getCreationTime))
3055+
//// .map(OpenPGPComponentSignature::getCreationTime)
3056+
//// .orElse(null);
3057+
// return chainLinks.stream()
3058+
// .map(new Function<Link, Object>()
3059+
// {
3060+
// @Override
3061+
// public OpenPGPComponentSignature apply(Link it)
3062+
// {
3063+
// return it.signature; // Replace lambda: `it -> it.signature`
3064+
// }
3065+
//
3066+
// })
3067+
// .max(new Comparator<Object>()
3068+
// {
3069+
// @Override
3070+
// public int compare(Object o1, Object o2)
3071+
// {
3072+
// // Replace method reference: `Comparator.comparing(OpenPGPComponentSignature::getCreationTime)`
3073+
// return ((OpenPGPComponentSignature)o1).getCreationTime().compareTo(((OpenPGPComponentSignature)o2).getCreationTime());
3074+
// }
3075+
// })
3076+
// .map(new Function<Object, Date>()
3077+
// {
3078+
// @Override
3079+
// public Date apply(Object sig)
3080+
// {
3081+
// return ((OpenPGPComponentSignature)sig).getCreationTime(); // Replace method reference: `OpenPGPComponentSignature::getCreationTime`
3082+
// }
3083+
// })
3084+
// .orElse(null);
3085+
// }
30723086

30733087
/**
30743088
* Return the date until which the chain link is valid.

pg/src/main/java/org/bouncycastle/openpgp/operator/bc/BcPGPKeyPairGeneratorProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public PGPKeyPair generateECDHKeyPair(ASN1ObjectIdentifier curveOID)
142142
{
143143
ECKeyPairGenerator gen = new ECKeyPairGenerator();
144144
gen.init(new ECKeyGenerationParameters(
145-
new ECNamedDomainParameters(curveOID, getNamedCurveByOid(curveOID)),
146-
CryptoServicesRegistrar.getSecureRandom()));
145+
new ECNamedDomainParameters(curveOID, getNamedCurveByOid(curveOID)),
146+
CryptoServicesRegistrar.getSecureRandom()));
147147

148148
AsymmetricCipherKeyPair keyPair = gen.generateKeyPair();
149149
return new BcPGPKeyPair(version, PublicKeyAlgorithmTags.ECDH, keyPair, creationTime);
@@ -155,8 +155,8 @@ public PGPKeyPair generateECDSAKeyPair(ASN1ObjectIdentifier curveOID)
155155
{
156156
ECKeyPairGenerator gen = new ECKeyPairGenerator();
157157
gen.init(new ECKeyGenerationParameters(
158-
new ECNamedDomainParameters(curveOID, getNamedCurveByOid(curveOID)),
159-
CryptoServicesRegistrar.getSecureRandom()));
158+
new ECNamedDomainParameters(curveOID, getNamedCurveByOid(curveOID)),
159+
CryptoServicesRegistrar.getSecureRandom()));
160160

161161
AsymmetricCipherKeyPair keyPair = gen.generateKeyPair();
162162
return new BcPGPKeyPair(version, PublicKeyAlgorithmTags.ECDSA, keyPair, creationTime);

0 commit comments

Comments
 (0)