org.bouncycastle.crypto.constraints.BitsOfSecurityConstraint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15to18 Show documentation
Show all versions of bcprov-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
package org.bouncycastle.crypto.constraints;
import java.util.Collections;
import java.util.Set;
import org.bouncycastle.crypto.CryptoServiceConstraintsException;
import org.bouncycastle.crypto.CryptoServiceProperties;
/**
* Basic bits of security constraint. Anything not of the required bits of security and
* not in the exception list will be rejected.
*/
public class BitsOfSecurityConstraint
extends ServicesConstraint
{
private final int requiredBitsOfSecurity;
public BitsOfSecurityConstraint(int requiredBitsOfSecurity)
{
super(Collections.EMPTY_SET);
this.requiredBitsOfSecurity = requiredBitsOfSecurity;
}
public BitsOfSecurityConstraint(int requiredBitsOfSecurity, Set exceptions)
{
super(exceptions);
this.requiredBitsOfSecurity = requiredBitsOfSecurity;
}
public void check(CryptoServiceProperties service)
{
if (isException(service.getServiceName()))
{
return;
}
if (service.bitsOfSecurity() < requiredBitsOfSecurity)
{
throw new CryptoServiceConstraintsException("service does not provide " + requiredBitsOfSecurity + " bits of security only " + service.bitsOfSecurity());
}
}
}