org.bouncycastle.jsse.provider.AbstractAlgorithmConstraints 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.security.Key;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.bouncycastle.jsse.java.security.BCAlgorithmConstraints;
import org.bouncycastle.jsse.java.security.BCCryptoPrimitive;
abstract class AbstractAlgorithmConstraints implements BCAlgorithmConstraints
{
protected final AlgorithmDecomposer decomposer;
AbstractAlgorithmConstraints(AlgorithmDecomposer decomposer)
{
this.decomposer = decomposer;
}
protected void checkAlgorithmName(String algorithm)
{
if (!JsseUtils.isNameSpecified(algorithm))
{
throw new IllegalArgumentException("No algorithm name specified");
}
}
protected void checkKey(Key key)
{
if (null == key)
{
throw new NullPointerException("'key' cannot be null");
}
}
protected void checkPrimitives(Set primitives)
{
if (!isPrimitivesSpecified(primitives))
{
throw new IllegalArgumentException("No cryptographic primitive specified");
}
}
protected boolean containsAnyPartIgnoreCase(Set elements, String algorithm)
{
if (elements.isEmpty())
{
return false;
}
if (containsIgnoreCase(elements, algorithm))
{
return true;
}
if (null != decomposer)
{
for (String part : decomposer.decompose(algorithm))
{
if (containsIgnoreCase(elements, part))
{
return true;
}
}
}
return false;
}
protected boolean containsIgnoreCase(Set elements, String s)
{
for (String element : elements)
{
if (element.equalsIgnoreCase(s))
{
return true;
}
}
return false;
}
protected boolean isPrimitivesSpecified(Set primitives)
{
return null != primitives && !primitives.isEmpty();
}
protected static Set asUnmodifiableSet(String[] algorithms)
{
if (null != algorithms && algorithms.length > 0)
{
Set result = asSet(algorithms);
if (!result.isEmpty())
{
return Collections.unmodifiableSet(result);
}
}
return Collections. emptySet();
}
protected static Set asSet(String[] algorithms)
{
Set result = new HashSet();
if (null != algorithms)
{
for (String algorithm : algorithms)
{
if (null != algorithm)
{
// TODO[jsse] toLowerCase?
result.add(algorithm);
}
}
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy