Minor - favor Guava's UTF-8 charset constant; sensible -> sensitive in issue template

This commit is contained in:
ljacqu 2016-09-16 23:38:36 +02:00
parent d1b7c0ed99
commit c1e90a8faf
5 changed files with 14 additions and 16 deletions

View File

@ -13,7 +13,7 @@ The actions that cause the issue
This can be found by running `/pl` This can be found by running `/pl`
### Environment description ### Environment description
Standalone server/Bungeecord network, SQLite/MYSql, ... Standalone server/Bungeecord network, SQLite/MySql, ...
### AuthMe build number: ### AuthMe build number:
This can be found by running `/authme version` This can be found by running `/authme version`
@ -22,4 +22,4 @@ This can be found by running `/authme version`
Pastebin/Hastebin/Gist link of the error logo or stacktrace (if any) Pastebin/Hastebin/Gist link of the error logo or stacktrace (if any)
### Configuration: ### Configuration:
Pastebin/Hastebin/Gist link of your config.yml file (remember to delete any sensible data) Pastebin/Hastebin/Gist link of your config.yml file (remember to delete any sensitive data)

View File

@ -1,15 +1,15 @@
package fr.xephi.authme.security.crypts; package fr.xephi.authme.security.crypts;
import com.google.common.base.Charsets;
import fr.xephi.authme.security.HashUtils; import fr.xephi.authme.security.HashUtils;
import fr.xephi.authme.security.MessageDigestAlgorithm; import fr.xephi.authme.security.MessageDigestAlgorithm;
import java.nio.charset.Charset;
import java.security.MessageDigest; import java.security.MessageDigest;
public class CRAZYCRYPT1 extends UsernameSaltMethod { public class CRAZYCRYPT1 extends UsernameSaltMethod {
private static final char[] CRYPTCHARS = private static final char[] CRYPTCHARS =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private final Charset charset = Charset.forName("UTF-8");
private static String byteArrayToHexString(final byte... args) { private static String byteArrayToHexString(final byte... args) {
final char[] chars = new char[args.length * 2]; final char[] chars = new char[args.length * 2];
@ -24,7 +24,7 @@ public class CRAZYCRYPT1 extends UsernameSaltMethod {
public HashedPassword computeHash(String password, String name) { public HashedPassword computeHash(String password, String name) {
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password; final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
final MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.SHA512); final MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.SHA512);
md.update(text.getBytes(charset), 0, text.length()); md.update(text.getBytes(Charsets.UTF_8), 0, text.length());
return new HashedPassword(byteArrayToHexString(md.digest())); return new HashedPassword(byteArrayToHexString(md.digest()));
} }

View File

@ -1,5 +1,6 @@
package fr.xephi.authme; package fr.xephi.authme;
import com.google.common.base.Charsets;
import fr.xephi.authme.output.LogLevel; import fr.xephi.authme.output.LogLevel;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
@ -17,7 +18,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -29,7 +29,6 @@ import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -92,7 +91,7 @@ public class ConsoleLoggerTest {
// then // then
verify(logger, times(2)).info(anyString()); verify(logger, times(2)).info(anyString());
verifyNoMoreInteractions(logger); verifyNoMoreInteractions(logger);
List<String> loggedLines = Files.readAllLines(logFile.toPath(), Charset.forName("UTF-8")); List<String> loggedLines = Files.readAllLines(logFile.toPath(), Charsets.UTF_8);
assertThat(loggedLines, hasSize(2)); assertThat(loggedLines, hasSize(2));
assertThat(loggedLines.get(0), containsString("[FINE] Logging a FINE message")); assertThat(loggedLines.get(0), containsString("[FINE] Logging a FINE message"));
assertThat(loggedLines.get(1), containsString("[INFO] This is an INFO message")); assertThat(loggedLines.get(1), containsString("[INFO] This is an INFO message"));
@ -130,7 +129,7 @@ public class ConsoleLoggerTest {
verify(logger).info("Info text"); verify(logger).info("Info text");
verify(logger).warning("Exception occurred: [IllegalStateException]: Test exception message"); verify(logger).warning("Exception occurred: [IllegalStateException]: Test exception message");
verifyNoMoreInteractions(logger); verifyNoMoreInteractions(logger);
List<String> loggedLines = Files.readAllLines(logFile.toPath(), Charset.forName("UTF-8")); List<String> loggedLines = Files.readAllLines(logFile.toPath(), Charsets.UTF_8);
assertThat(loggedLines.size(), greaterThan(3)); assertThat(loggedLines.size(), greaterThan(3));
assertThat(loggedLines.get(0), containsString("[INFO] Info text")); assertThat(loggedLines.get(0), containsString("[INFO] Info text"));
assertThat(loggedLines.get(1), assertThat(loggedLines.get(1),

View File

@ -1,5 +1,6 @@
package tools.messages.translation; package tools.messages.translation;
import com.google.common.base.Charsets;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import com.google.gson.Gson; import com.google.gson.Gson;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
@ -14,7 +15,6 @@ import tools.utils.ToolsConstants;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashSet; import java.util.HashSet;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; import java.util.Set;
@ -56,7 +56,7 @@ public class ImportMessagesTask implements ToolTask {
private LanguageExport getLanguageExportFromUrl(String location) { private LanguageExport getLanguageExportFromUrl(String location) {
try { try {
URL url = new URL(location); URL url = new URL(location);
String json = Resources.toString(url, Charset.forName("UTF-8")); String json = Resources.toString(url, Charsets.UTF_8);
return gson.fromJson(json, LanguageExport.class); return gson.fromJson(json, LanguageExport.class);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);

View File

@ -1,7 +1,8 @@
package tools.utils; package tools.utils;
import com.google.common.base.Charsets;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
@ -12,8 +13,6 @@ import java.util.List;
*/ */
public final class FileUtils { public final class FileUtils {
private final static Charset CHARSET = Charset.forName("utf-8");
private FileUtils() { private FileUtils() {
} }
@ -41,7 +40,7 @@ public final class FileUtils {
public static String readFromFile(String file) { public static String readFromFile(String file) {
try { try {
return new String(Files.readAllBytes(Paths.get(file)), CHARSET); return new String(Files.readAllBytes(Paths.get(file)), Charsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
throw new UnsupportedOperationException("Could not read from file '" + file + "'", e); throw new UnsupportedOperationException("Could not read from file '" + file + "'", e);
} }
@ -49,7 +48,7 @@ public final class FileUtils {
public static List<String> readLinesFromFile(String file) { public static List<String> readLinesFromFile(String file) {
try { try {
return Files.readAllLines(Paths.get(file), CHARSET); return Files.readAllLines(Paths.get(file), Charsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
throw new UnsupportedOperationException("Could not read from file '" + file + "'", e); throw new UnsupportedOperationException("Could not read from file '" + file + "'", e);
} }