All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.constraints.BitsOfSecurityConstraint Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.79
Show newest version
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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy