1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Hide utility class constructors

Update all utility classes so that they have a private constructor. This
prevents users from accidentally creating an instance, when they should
just use the static methods directly.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-29 15:15:15 -07:00
committed by Rob Winch
parent 8559447357
commit 01d90c9881
61 changed files with 213 additions and 52 deletions
@@ -29,12 +29,15 @@ import org.bouncycastle.util.Arrays;
* @author Simeon Macke
* @since 5.3
*/
class Argon2EncodingUtils {
final class Argon2EncodingUtils {
private static final Base64.Encoder b64encoder = Base64.getEncoder().withoutPadding();
private static final Base64.Decoder b64decoder = Base64.getDecoder();
private Argon2EncodingUtils() {
}
/**
* Encodes a raw Argon2-hash and its parameters into the standard Argon2-hash-string
* as specified in the reference implementation
@@ -237,6 +237,9 @@ public final class Base64 {
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
};
private Base64() {
}
public static byte[] decode(byte[] bytes) {
return decode(bytes, 0, bytes.length, NO_OPTIONS);
}
@@ -30,6 +30,9 @@ public final class Hex {
private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
'f' };
private Hex() {
}
public static char[] encode(byte[] bytes) {
final int nBytes = bytes.length;
char[] result = new char[2 * nBytes];
@@ -33,6 +33,9 @@ public final class Utf8 {
private static final Charset CHARSET = StandardCharsets.UTF_8;
private Utf8() {
}
/**
* Get the bytes of the String in UTF-8 encoded form.
*/
@@ -28,8 +28,6 @@ public class Base64Tests {
@Test
public void isBase64ReturnsTrueForValidBase64() {
new Base64(); // unused
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D' })).isTrue();
}
@@ -26,7 +26,10 @@ import org.junit.AssumptionViolatedException;
import org.springframework.security.crypto.encrypt.AesBytesEncryptor.CipherAlgorithm;
public class CryptoAssumptions {
public final class CryptoAssumptions {
private CryptoAssumptions() {
}
public static void assumeGCMJCE() {
assumeAes256(CipherAlgorithm.GCM);