Revert unnecessary merges on 6.0.x
This commit removes unnecessary main-branch merges starting from8750608b5band adds the following needed commit(s) that were made afterward: -5dce82c48b
This commit is contained in:
@@ -58,13 +58,19 @@ final class Argon2EncodingUtils {
|
||||
*/
|
||||
static String encode(byte[] hash, Argon2Parameters parameters) throws IllegalArgumentException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String type = switch (parameters.getType()) {
|
||||
case Argon2Parameters.ARGON2_d -> "$argon2d";
|
||||
case Argon2Parameters.ARGON2_i -> "$argon2i";
|
||||
case Argon2Parameters.ARGON2_id -> "$argon2id";
|
||||
default -> throw new IllegalArgumentException("Invalid algorithm type: " + parameters.getType());
|
||||
};
|
||||
stringBuilder.append(type);
|
||||
switch (parameters.getType()) {
|
||||
case Argon2Parameters.ARGON2_d:
|
||||
stringBuilder.append("$argon2d");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_i:
|
||||
stringBuilder.append("$argon2i");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_id:
|
||||
stringBuilder.append("$argon2id");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parameters.getType());
|
||||
}
|
||||
stringBuilder.append("$v=")
|
||||
.append(parameters.getVersion())
|
||||
.append("$m=")
|
||||
@@ -107,12 +113,19 @@ final class Argon2EncodingUtils {
|
||||
throw new IllegalArgumentException("Invalid encoded Argon2-hash");
|
||||
}
|
||||
int currentPart = 1;
|
||||
paramsBuilder = switch (parts[currentPart++]) {
|
||||
case "argon2d" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d);
|
||||
case "argon2i" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i);
|
||||
case "argon2id" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
|
||||
default -> throw new IllegalArgumentException("Invalid algorithm type: " + parts[0]);
|
||||
};
|
||||
switch (parts[currentPart++]) {
|
||||
case "argon2d":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d);
|
||||
break;
|
||||
case "argon2i":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i);
|
||||
break;
|
||||
case "argon2id":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parts[0]);
|
||||
}
|
||||
if (parts[currentPart].startsWith("v=")) {
|
||||
paramsBuilder.withVersion(Integer.parseInt(parts[currentPart].substring(2)));
|
||||
currentPart++;
|
||||
|
||||
@@ -390,7 +390,7 @@ public class BCryptTests {
|
||||
Arrays.fill(ba, (byte) 0);
|
||||
ba[i] = (byte) b;
|
||||
String s = encode_base64(ba, 3);
|
||||
assertThat(s).hasSize(4);
|
||||
assertThat(s.length()).isEqualTo(4);
|
||||
byte[] decoded = BCrypt.decode_base64(s, 3);
|
||||
assertThat(decoded).isEqualTo(ba);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -28,8 +29,6 @@ import org.springframework.security.crypto.encrypt.AesBytesEncryptor.CipherAlgor
|
||||
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||
|
||||
private byte[] testData;
|
||||
@@ -97,11 +96,11 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||
// and can decrypt back to the original input
|
||||
byte[] leftEncrypted = left.encrypt(this.testData);
|
||||
byte[] rightEncrypted = right.encrypt(this.testData);
|
||||
assertThat(rightEncrypted).containsExactly(leftEncrypted);
|
||||
Assertions.assertArrayEquals(leftEncrypted, rightEncrypted);
|
||||
byte[] leftDecrypted = left.decrypt(leftEncrypted);
|
||||
byte[] rightDecrypted = right.decrypt(rightEncrypted);
|
||||
assertThat(leftDecrypted).containsExactly(this.testData);
|
||||
assertThat(rightDecrypted).containsExactly(this.testData);
|
||||
Assertions.assertArrayEquals(this.testData, leftDecrypted);
|
||||
Assertions.assertArrayEquals(this.testData, rightDecrypted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,8 +114,8 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||
byte[] rightEncrypted = right.encrypt(this.testData);
|
||||
byte[] leftDecrypted = left.decrypt(rightEncrypted);
|
||||
byte[] rightDecrypted = right.decrypt(leftEncrypted);
|
||||
assertThat(leftDecrypted).containsExactly(this.testData);
|
||||
assertThat(rightDecrypted).containsExactly(this.testData);
|
||||
Assertions.assertArrayEquals(this.testData, leftDecrypted);
|
||||
Assertions.assertArrayEquals(this.testData, rightDecrypted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ import java.security.SecureRandom;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bouncycastle.util.Arrays;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
public class BouncyCastleAesBytesEncryptorTests {
|
||||
@@ -64,11 +64,11 @@ public class BouncyCastleAesBytesEncryptorTests {
|
||||
private void generatesDifferentCipherTexts(BytesEncryptor bcEncryptor) {
|
||||
byte[] encrypted1 = bcEncryptor.encrypt(this.testData);
|
||||
byte[] encrypted2 = bcEncryptor.encrypt(this.testData);
|
||||
assertThat(Arrays.areEqual(encrypted1, encrypted2)).isFalse();
|
||||
Assertions.assertFalse(Arrays.areEqual(encrypted1, encrypted2));
|
||||
byte[] decrypted1 = bcEncryptor.decrypt(encrypted1);
|
||||
byte[] decrypted2 = bcEncryptor.decrypt(encrypted2);
|
||||
assertThat(decrypted1).containsExactly(this.testData);
|
||||
assertThat(decrypted2).containsExactly(this.testData);
|
||||
Assertions.assertArrayEquals(this.testData, decrypted1);
|
||||
Assertions.assertArrayEquals(this.testData, decrypted2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -60,7 +60,7 @@ public class KeyGeneratorsTests {
|
||||
public void string() {
|
||||
StringKeyGenerator keyGenerator = KeyGenerators.string();
|
||||
String hexStringKey = keyGenerator.generateKey();
|
||||
assertThat(hexStringKey).hasSize(16);
|
||||
assertThat(hexStringKey.length()).isEqualTo(16);
|
||||
assertThat(Hex.decode(hexStringKey)).hasSize(8);
|
||||
String hexStringKey2 = keyGenerator.generateKey();
|
||||
assertThat(hexStringKey.equals(hexStringKey2)).isFalse();
|
||||
|
||||
@@ -39,8 +39,8 @@ public class Pbkdf2PasswordEncoderTests {
|
||||
// encode output is an hex coded String so with 2 chars per encoding result byte
|
||||
// (ie. 1 char for 4 bits).
|
||||
// The encoding result size is : (saltLength * 8) bits + hashWith bits.
|
||||
assertThat(this.encoder.encode("password")).hasSize((8 * 8 + 256) / 4);
|
||||
assertThat(this.encoderSalt16.encode("password")).hasSize((16 * 8 + 256) / 4);
|
||||
assertThat(this.encoder.encode("password").length()).isEqualTo((8 * 8 + 256) / 4);
|
||||
assertThat(this.encoderSalt16.encode("password").length()).isEqualTo((16 * 8 + 256) / 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user