Skip to content

Commit

Permalink
Use Charset constant where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Dec 17, 2024
1 parent ca0562e commit 7da0638
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/main/java/hudson/plugins/ec2/EC2PrivateKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -147,7 +146,7 @@ public String decryptWindowsPassword(String encodedPassword) throws AmazonClient
PEMEncodable.decode(privateKey.getPlainText()).toPrivateKey());
byte[] cipherText = Base64.getDecoder().decode(StringUtils.deleteWhitespace(encodedPassword));
byte[] plainText = cipher.doFinal(cipherText);
return new String(plainText, Charset.forName("ASCII"));
return new String(plainText, StandardCharsets.US_ASCII);
} catch (Exception e) {
throw new AmazonClientException("Unable to decode password:\n" + e.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
&& !initScript.trim().isEmpty()
&& conn.exec("test -e ~/.hudson-run-init", logger) != 0) {
logInfo(computer, listener, "Executing init script");
scp.put(initScript.getBytes("UTF-8"), "init.sh", tmpDir, "0700");
scp.put(initScript.getBytes(StandardCharsets.UTF_8), "init.sh", tmpDir, "0700");
Session sess = conn.openSession();
sess.requestDumbPTY(); // so that the remote side bundles stdout
// and stderr
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
&& !initScript.trim().isEmpty()
&& conn.exec("test -e ~/.hudson-run-init", logger) != 0) {
logInfo(computer, listener, "Executing init script");
scp.put(initScript.getBytes("UTF-8"), "init.sh", tmpDir, "0700");
scp.put(initScript.getBytes(StandardCharsets.UTF_8), "init.sh", tmpDir, "0700");
Session sess = conn.openSession();
sess.requestDumbPTY(); // so that the remote side bundles stdout
// and stderr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
if (initScript != null && !initScript.trim().isEmpty() && !connection.exists(tmpDir + ".jenkins-init")) {
logger.println("Executing init script");
try (OutputStream init = connection.putFile(tmpDir + "init.bat")) {
init.write(initScript.getBytes("utf-8"));
init.write(initScript.getBytes(StandardCharsets.UTF_8));
}

WindowsProcess initProcess = connection.execute("cmd /c " + tmpDir + "init.bat");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.nio.charset.StandardCharsets;
import org.junit.Test;

public class HostKeyVerifierImplTest {
Expand All @@ -13,12 +14,12 @@ public class HostKeyVerifierImplTest {
@Test
public void testVerifyFail() throws Exception {
HostKeyVerifierImpl impl = new HostKeyVerifierImpl("");
assertFalse(impl.verifyServerHostKey("", 0, null, key.getBytes("UTF-8")));
assertFalse(impl.verifyServerHostKey("", 0, null, key.getBytes(StandardCharsets.UTF_8)));
}

@Test
public void testVerifyTrue() throws Exception {
HostKeyVerifierImpl impl = new HostKeyVerifierImpl(fp);
assertTrue(impl.verifyServerHostKey("", 0, null, key.getBytes("UTF-8")));
assertTrue(impl.verifyServerHostKey("", 0, null, key.getBytes(StandardCharsets.UTF_8)));
}
}

0 comments on commit 7da0638

Please sign in to comment.