org.bouncycastle.jsse.provider.JcaAlgorithmDecomposer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bctls-fips Show documentation
Show all versions of bctls-fips Show documentation
The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
package org.bouncycastle.jsse.provider;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
class JcaAlgorithmDecomposer
implements AlgorithmDecomposer
{
private static final Pattern PATTERN = Pattern.compile("with|and|(? decompose(String algorithm)
{
if (algorithm.indexOf('/') < 0)
{
return Collections.emptySet();
}
Set result = new HashSet();
for (String section : algorithm.split("/"))
{
if (section.length() > 0)
{
for (String part : PATTERN.split(section))
{
if (part.length() > 0)
{
result.add(part);
}
}
}
}
ensureBothIfEither(result, "SHA1", "SHA-1");
ensureBothIfEither(result, "SHA224", "SHA-224");
ensureBothIfEither(result, "SHA256", "SHA-256");
ensureBothIfEither(result, "SHA384", "SHA-384");
ensureBothIfEither(result, "SHA512", "SHA-512");
return result;
}
private static void ensureBothIfEither(Set elements, String a, String b)
{
boolean hasA = elements.contains(a), hasB = elements.contains(b);
if (hasA ^ hasB)
{
elements.add(hasA ? b : a);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy