Skip to content

Commit 6acd186

Browse files
committed
Minor syntax changes
1 parent ef7244d commit 6acd186

File tree

12 files changed

+21
-23
lines changed

12 files changed

+21
-23
lines changed

jsign-ant/src/test/java/net/jsign/JsignTaskTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public void testReplaceSignature() throws Exception {
289289
}
290290

291291
@Test
292-
public void testDetachedSignature() throws Exception {
292+
public void testDetachedSignature() {
293293
project.executeTarget("detach-signature");
294294

295295
assertTrue("Signature wasn't detached", new File("target/test-classes/wineyes-signed-detached.exe.sig").exists());

jsign-cli/src/main/java/net/jsign/DirectoryScanner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ String globToRegExp(String glob) {
124124
ignoreNextSeparator = true;
125125
} else if (token.contains("*")) {
126126
ignoreNextSeparator = false;
127-
pattern.append("\\Q" + token.replaceAll("\\*", "\\\\E[^/]*\\\\Q") + "\\E");
127+
pattern.append("\\Q").append(token.replaceAll("\\*", "\\\\E[^/]*\\\\Q")).append("\\E");
128128
} else {
129129
ignoreNextSeparator = false;
130130
pattern.append("\\Q").append(token).append("\\E");

jsign-core/src/main/java/net/jsign/SignerHelper.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.bouncycastle.asn1.DERUTF8String;
5454
import org.bouncycastle.asn1.cms.AttributeTable;
5555
import org.bouncycastle.asn1.cms.ContentInfo;
56-
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
5756
import org.bouncycastle.cert.X509CertificateHolder;
5857
import org.bouncycastle.cms.CMSException;
5958
import org.bouncycastle.cms.CMSProcessable;
@@ -683,7 +682,7 @@ private void timestamp(File file) throws SignerException {
683682
*/
684683
private void initializeProxy(String proxyUrl, final String proxyUser, final String proxyPassword) throws MalformedURLException {
685684
// Do nothing if there is no proxy url.
686-
if (proxyUrl != null && proxyUrl.trim().length() > 0) {
685+
if (proxyUrl != null && !proxyUrl.trim().isEmpty()) {
687686
if (!proxyUrl.trim().startsWith("http")) {
688687
proxyUrl = "http://" + proxyUrl.trim();
689688
}
@@ -706,7 +705,7 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
706705
}
707706
});
708707

709-
if (proxyUser != null && proxyUser.length() > 0 && proxyPassword != null) {
708+
if (proxyUser != null && !proxyUser.isEmpty() && proxyPassword != null) {
710709
Authenticator.setDefault(new Authenticator() {
711710
protected PasswordAuthentication getPasswordAuthentication() {
712711
return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray());

jsign-core/src/main/java/net/jsign/navx/NAVXSignatureBlock.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public void read(SeekableByteChannel channel) throws IOException {
6565
byte[] signatureBytes = new byte[size - 8];
6666
buffer.position(4);
6767
buffer.get(signatureBytes);
68-
try {
69-
signedData = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(signatureBytes).readObject()));
68+
try (ASN1InputStream in = new ASN1InputStream(signatureBytes)) {
69+
signedData = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(in.readObject()));
7070
} catch (CMSException | StackOverflowError e) {
7171
throw new IOException("Invalid CMS signature", e);
7272
}

jsign-core/src/main/java/net/jsign/pe/CertificateTableEntry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public CMSSignedData getSignature() throws CMSException {
7474
}
7575

7676
if (signature == null) {
77-
try {
78-
signature = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(content).readObject()));
77+
try (ASN1InputStream in = new ASN1InputStream(content)) {
78+
signature = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(in.readObject()));
7979
} catch (IOException | StackOverflowError e) {
8080
throw new IllegalArgumentException("Failed to construct ContentInfo from byte[]: ", e);
8181
}

jsign-core/src/main/java/net/jsign/script/SignableScript.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ private String createSignatureBlock(CMSSignedData signature) throws IOException
220220

221221
StringBuilder signatureBlock = new StringBuilder();
222222
signatureBlock.append("\r\n");
223-
signatureBlock.append(getSignatureStart() + "\r\n");
223+
signatureBlock.append(getSignatureStart()).append("\r\n");
224224
for (int start = 0, blobLength = signatureBlob.length(); start < blobLength; start += 64) {
225225
signatureBlock.append(getLineCommentStart());
226226
signatureBlock.append(signatureBlob, start, min(blobLength, start + 64));
227227
signatureBlock.append(getLineCommentEnd());
228228
signatureBlock.append("\r\n");
229229
}
230-
signatureBlock.append(getSignatureEnd() + "\r\n");
230+
signatureBlock.append(getSignatureEnd()).append("\r\n");
231231

232232
return signatureBlock.toString();
233233
}

jsign-crypto/src/main/java/net/jsign/CertificateUtils.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ public static boolean isSelfSigned(X509Certificate certificate) {
159159
* @since 7.0
160160
*/
161161
public static List<X509Certificate> getFullCertificateChain(Collection<X509Certificate> chain) {
162-
Set<String> issuerNames = chain.stream().map(c -> c.getIssuerX500Principal().getName()).collect(Collectors.toSet());
163-
164-
Set<String> missingIssuerNames = new LinkedHashSet<>(issuerNames);
162+
Set<String> missingIssuerNames = chain.stream().map(c -> c.getIssuerX500Principal().getName())
163+
.collect(Collectors.toCollection(LinkedHashSet::new));
165164
for (X509Certificate certificate : chain) {
166165
missingIssuerNames.remove(certificate.getSubjectX500Principal().getName());
167166
}

jsign-crypto/src/main/java/net/jsign/jca/AzureTrustedSigningService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.security.cert.Certificate;
2626
import java.security.cert.CertificateException;
2727
import java.security.cert.CertificateFactory;
28-
import java.util.ArrayList;
2928
import java.util.Base64;
3029
import java.util.Collection;
30+
import java.util.Collections;
3131
import java.util.HashMap;
3232
import java.util.List;
3333
import java.util.Map;
@@ -94,7 +94,7 @@ public String getName() {
9494

9595
@Override
9696
public List<String> aliases() throws KeyStoreException {
97-
return new ArrayList<>();
97+
return Collections.emptyList();
9898
}
9999

100100
@Override

jsign-crypto/src/test/java/net/jsign/KeyStoreTypeTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public class KeyStoreTypeTest {
2828

2929
@Test
30-
public void testGetType() throws Exception {
30+
public void testGetType() {
3131
assertEquals(PKCS12, KeyStoreType.of(new File("keystore.p12")));
3232
assertEquals(PKCS12, KeyStoreType.of(new File("keystore.pfx")));
3333
assertEquals(JCEKS, KeyStoreType.of(new File("keystore.jceks")));
@@ -63,7 +63,7 @@ public void testGetTypeJKSFromHeader() throws Exception {
6363
}
6464

6565
@Test
66-
public void testGetTypeUnknown() throws Exception {
66+
public void testGetTypeUnknown() {
6767
assertNull(KeyStoreType.of(new File("target/test-classes/keystores/jsign-root-ca.pem")));
6868
}
6969
}

jsign-crypto/src/test/java/net/jsign/jca/AmazonIMDS2ClientTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void testNoInstanceProfile() {
104104
AmazonIMDS2Client client = new AmazonIMDS2Client();
105105
client.setEndpoint("http://localhost:" + port());
106106

107-
Exception e = assertThrows(RuntimeException.class, () -> client.getCredentials());
107+
Exception e = assertThrows(RuntimeException.class, client::getCredentials);
108108
assertEquals("message", "This EC2 instance seems not to be associated with an instance profile", e.getMessage());
109109
}
110110

@@ -134,7 +134,7 @@ public void testGetInstanceProfileName() throws Exception {
134134
}
135135

136136
@Test
137-
public void testInvalidInstanceProfileName() throws Exception {
137+
public void testInvalidInstanceProfileName() {
138138
onRequest()
139139
.havingMethodEqualTo("PUT")
140140
.havingPathEqualTo("/latest/api/token")

jsign-crypto/src/test/java/net/jsign/jca/OpenPGPCardTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
public class OpenPGPCardTest {
3434

35-
public static void assumeCardPresent() throws Exception {
35+
public static void assumeCardPresent() {
3636
try {
3737
assumeTrue("OpenPGP card not found", SmartCard.getTerminal("Nitrokey") != null);
3838
} catch (CardException e) {

jsign-crypto/src/test/java/net/jsign/jca/TLVTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class TLVTest {
2727

2828
@Test
29-
public void testParseList() throws Exception {
29+
public void testParseList() {
3030
byte[] data = Hex.decode("01 01 86 02 02 05 05 08 04 01 26 9A 33".replaceAll(" ", ""));
3131
TLV tlv = TLV.parse(ByteBuffer.wrap(data));
3232

@@ -69,7 +69,7 @@ public void testWriteLength() {
6969
}
7070

7171
@Test
72-
public void testEncode() throws Exception {
72+
public void testEncode() {
7373
byte[] data = Hex.decode("01 01 86 02 02 05 05 08 04 01 26 9A 33".replaceAll(" ", ""));
7474
TLV tlv = TLV.parse(ByteBuffer.wrap(data));
7575

0 commit comments

Comments
 (0)