CertificateMatchingTestSource Class — spring-boot Architecture
Architecture documentation for the CertificateMatchingTestSource class in CertificateMatchingTestSource.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/CertificateMatchingTestSource.java lines 51–127
record CertificateMatchingTestSource(CertificateMatchingTestSource.Algorithm algorithm, PrivateKey privateKey,
X509Certificate matchingCertificate, List<X509Certificate> nonMatchingCertificates,
List<PrivateKey> nonMatchingPrivateKeys) {
private static final List<Algorithm> ALGORITHMS;
static {
List<Algorithm> algorithms = new ArrayList<>();
Stream.of("RSA", "DSA", "ed25519", "ed448").map(Algorithm::of).forEach(algorithms::add);
Stream.of("secp256r1", "secp521r1").map(Algorithm::ec).forEach(algorithms::add);
ALGORITHMS = List.copyOf(algorithms);
}
CertificateMatchingTestSource(Algorithm algorithm, KeyPair matchingKeyPair, List<KeyPair> nonMatchingKeyPairs) {
this(algorithm, matchingKeyPair.getPrivate(), asCertificate(matchingKeyPair),
nonMatchingKeyPairs.stream().map(CertificateMatchingTestSource::asCertificate).toList(),
nonMatchingKeyPairs.stream().map(KeyPair::getPrivate).toList());
}
private static X509Certificate asCertificate(KeyPair keyPair) {
X509Certificate certificate = mock(X509Certificate.class);
given(certificate.getPublicKey()).willReturn(keyPair.getPublic());
return certificate;
}
@Override
public String toString() {
return this.algorithm.toString();
}
static List<CertificateMatchingTestSource> create()
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Map<Algorithm, KeyPair> keyPairs = new LinkedHashMap<>();
for (Algorithm algorithm : ALGORITHMS) {
keyPairs.put(algorithm, algorithm.generateKeyPair());
}
List<CertificateMatchingTestSource> parameters = new ArrayList<>();
keyPairs.forEach((algorithm, matchingKeyPair) -> {
List<KeyPair> nonMatchingKeyPairs = new ArrayList<>(keyPairs.values());
nonMatchingKeyPairs.remove(matchingKeyPair);
parameters.add(new CertificateMatchingTestSource(algorithm, matchingKeyPair, nonMatchingKeyPairs));
});
return List.copyOf(parameters);
}
/**
* An individual algorithm.
*
* @param name the algorithm name
* @param spec the algorithm spec or {@code null}
*/
record Algorithm(String name, @Nullable AlgorithmParameterSpec spec) {
KeyPair generateKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
KeyPairGenerator generator = KeyPairGenerator.getInstance(this.name);
if (this.spec != null) {
generator.initialize(this.spec);
}
return generator.generateKeyPair();
}
@Override
public String toString() {
String spec = (this.spec instanceof NamedParameterSpec namedSpec) ? namedSpec.getName() : "";
return this.name + ((!spec.isEmpty()) ? ":" + spec : "");
}
static Algorithm of(String name) {
return new Algorithm(name, null);
}
static Algorithm ec(String curve) {
return new Algorithm("EC", new ECGenParameterSpec(curve));
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free