Skip to content

Commit

Permalink
Minor syntax changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ebourg committed Nov 15, 2024
1 parent ef7244d commit 6acd186
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion jsign-ant/src/test/java/net/jsign/JsignTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void testReplaceSignature() throws Exception {
}

@Test
public void testDetachedSignature() throws Exception {
public void testDetachedSignature() {
project.executeTarget("detach-signature");

assertTrue("Signature wasn't detached", new File("target/test-classes/wineyes-signed-detached.exe.sig").exists());
Expand Down
2 changes: 1 addition & 1 deletion jsign-cli/src/main/java/net/jsign/DirectoryScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ String globToRegExp(String glob) {
ignoreNextSeparator = true;
} else if (token.contains("*")) {
ignoreNextSeparator = false;
pattern.append("\\Q" + token.replaceAll("\\*", "\\\\E[^/]*\\\\Q") + "\\E");
pattern.append("\\Q").append(token.replaceAll("\\*", "\\\\E[^/]*\\\\Q")).append("\\E");
} else {
ignoreNextSeparator = false;
pattern.append("\\Q").append(token).append("\\E");
Expand Down
5 changes: 2 additions & 3 deletions jsign-core/src/main/java/net/jsign/SignerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessable;
Expand Down Expand Up @@ -683,7 +682,7 @@ private void timestamp(File file) throws SignerException {
*/
private void initializeProxy(String proxyUrl, final String proxyUser, final String proxyPassword) throws MalformedURLException {
// Do nothing if there is no proxy url.
if (proxyUrl != null && proxyUrl.trim().length() > 0) {
if (proxyUrl != null && !proxyUrl.trim().isEmpty()) {
if (!proxyUrl.trim().startsWith("http")) {
proxyUrl = "http://" + proxyUrl.trim();
}
Expand All @@ -706,7 +705,7 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
}
});

if (proxyUser != null && proxyUser.length() > 0 && proxyPassword != null) {
if (proxyUser != null && !proxyUser.isEmpty() && proxyPassword != null) {
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void read(SeekableByteChannel channel) throws IOException {
byte[] signatureBytes = new byte[size - 8];
buffer.position(4);
buffer.get(signatureBytes);
try {
signedData = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(signatureBytes).readObject()));
try (ASN1InputStream in = new ASN1InputStream(signatureBytes)) {
signedData = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(in.readObject()));
} catch (CMSException | StackOverflowError e) {
throw new IOException("Invalid CMS signature", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public CMSSignedData getSignature() throws CMSException {
}

if (signature == null) {
try {
signature = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(content).readObject()));
try (ASN1InputStream in = new ASN1InputStream(content)) {
signature = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(in.readObject()));
} catch (IOException | StackOverflowError e) {
throw new IllegalArgumentException("Failed to construct ContentInfo from byte[]: ", e);
}
Expand Down
4 changes: 2 additions & 2 deletions jsign-core/src/main/java/net/jsign/script/SignableScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ private String createSignatureBlock(CMSSignedData signature) throws IOException

StringBuilder signatureBlock = new StringBuilder();
signatureBlock.append("\r\n");
signatureBlock.append(getSignatureStart() + "\r\n");
signatureBlock.append(getSignatureStart()).append("\r\n");
for (int start = 0, blobLength = signatureBlob.length(); start < blobLength; start += 64) {
signatureBlock.append(getLineCommentStart());
signatureBlock.append(signatureBlob, start, min(blobLength, start + 64));
signatureBlock.append(getLineCommentEnd());
signatureBlock.append("\r\n");
}
signatureBlock.append(getSignatureEnd() + "\r\n");
signatureBlock.append(getSignatureEnd()).append("\r\n");

return signatureBlock.toString();
}
Expand Down
5 changes: 2 additions & 3 deletions jsign-crypto/src/main/java/net/jsign/CertificateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ public static boolean isSelfSigned(X509Certificate certificate) {
* @since 7.0
*/
public static List<X509Certificate> getFullCertificateChain(Collection<X509Certificate> chain) {
Set<String> issuerNames = chain.stream().map(c -> c.getIssuerX500Principal().getName()).collect(Collectors.toSet());

Set<String> missingIssuerNames = new LinkedHashSet<>(issuerNames);
Set<String> missingIssuerNames = chain.stream().map(c -> c.getIssuerX500Principal().getName())
.collect(Collectors.toCollection(LinkedHashSet::new));
for (X509Certificate certificate : chain) {
missingIssuerNames.remove(certificate.getSubjectX500Principal().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -94,7 +94,7 @@ public String getName() {

@Override
public List<String> aliases() throws KeyStoreException {
return new ArrayList<>();
return Collections.emptyList();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions jsign-crypto/src/test/java/net/jsign/KeyStoreTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class KeyStoreTypeTest {

@Test
public void testGetType() throws Exception {
public void testGetType() {
assertEquals(PKCS12, KeyStoreType.of(new File("keystore.p12")));
assertEquals(PKCS12, KeyStoreType.of(new File("keystore.pfx")));
assertEquals(JCEKS, KeyStoreType.of(new File("keystore.jceks")));
Expand Down Expand Up @@ -63,7 +63,7 @@ public void testGetTypeJKSFromHeader() throws Exception {
}

@Test
public void testGetTypeUnknown() throws Exception {
public void testGetTypeUnknown() {
assertNull(KeyStoreType.of(new File("target/test-classes/keystores/jsign-root-ca.pem")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testNoInstanceProfile() {
AmazonIMDS2Client client = new AmazonIMDS2Client();
client.setEndpoint("http://localhost:" + port());

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

Expand Down Expand Up @@ -134,7 +134,7 @@ public void testGetInstanceProfileName() throws Exception {
}

@Test
public void testInvalidInstanceProfileName() throws Exception {
public void testInvalidInstanceProfileName() {
onRequest()
.havingMethodEqualTo("PUT")
.havingPathEqualTo("/latest/api/token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class OpenPGPCardTest {

public static void assumeCardPresent() throws Exception {
public static void assumeCardPresent() {
try {
assumeTrue("OpenPGP card not found", SmartCard.getTerminal("Nitrokey") != null);
} catch (CardException e) {
Expand Down
4 changes: 2 additions & 2 deletions jsign-crypto/src/test/java/net/jsign/jca/TLVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class TLVTest {

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

Expand Down Expand Up @@ -69,7 +69,7 @@ public void testWriteLength() {
}

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

Expand Down

0 comments on commit 6acd186

Please sign in to comment.