// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.crypto.constraints;

import java.util.logging.Level;
import org.bouncycastle.crypto.CryptoServicePurpose;
import org.bouncycastle.crypto.CryptoServiceConstraintsException;
import org.bouncycastle.crypto.CryptoServiceProperties;
import java.util.Set;
import java.util.Collections;

public class LegacyBitsOfSecurityConstraint extends ServicesConstraint
{
    private final int requiredBitsOfSecurity;
    private final int legacyRequiredBitsOfSecurity;
    
    public LegacyBitsOfSecurityConstraint(final int n) {
        this(n, 0);
    }
    
    public LegacyBitsOfSecurityConstraint(final int requiredBitsOfSecurity, final int legacyRequiredBitsOfSecurity) {
        super(Collections.EMPTY_SET);
        this.requiredBitsOfSecurity = requiredBitsOfSecurity;
        this.legacyRequiredBitsOfSecurity = legacyRequiredBitsOfSecurity;
    }
    
    public LegacyBitsOfSecurityConstraint(final int n, final Set<String> set) {
        this(n, 0, set);
    }
    
    public LegacyBitsOfSecurityConstraint(final int requiredBitsOfSecurity, final int legacyRequiredBitsOfSecurity, final Set<String> set) {
        super(set);
        this.requiredBitsOfSecurity = requiredBitsOfSecurity;
        this.legacyRequiredBitsOfSecurity = legacyRequiredBitsOfSecurity;
    }
    
    @Override
    public void check(final CryptoServiceProperties cryptoServiceProperties) {
        if (this.isException(cryptoServiceProperties.getServiceName())) {
            return;
        }
        final CryptoServicePurpose purpose = cryptoServiceProperties.getPurpose();
        switch (purpose) {
            case ANY:
            case VERIFYING:
            case DECRYPTION:
            case VERIFICATION: {
                if (cryptoServiceProperties.bitsOfSecurity() < this.legacyRequiredBitsOfSecurity) {
                    throw new CryptoServiceConstraintsException("service does not provide " + this.legacyRequiredBitsOfSecurity + " bits of security only " + cryptoServiceProperties.bitsOfSecurity());
                }
                if (purpose != CryptoServicePurpose.ANY && LegacyBitsOfSecurityConstraint.LOG.isLoggable(Level.FINE)) {
                    LegacyBitsOfSecurityConstraint.LOG.fine("usage of legacy cryptography service for algorithm " + cryptoServiceProperties.getServiceName());
                }
                return;
            }
            default: {
                if (cryptoServiceProperties.bitsOfSecurity() < this.requiredBitsOfSecurity) {
                    throw new CryptoServiceConstraintsException("service does not provide " + this.requiredBitsOfSecurity + " bits of security only " + cryptoServiceProperties.bitsOfSecurity());
                }
            }
        }
    }
}
