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

package org.bouncycastle.pkcs.bc;

import java.io.IOException;
import org.bouncycastle.asn1.pkcs.PBMAC1Params;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.pkcs.PKCS12MacCalculatorBuilder;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.pkcs.PKCS12MacCalculatorBuilderProvider;

public class BcPKCS12PBMac1CalculatorBuilderProvider implements PKCS12MacCalculatorBuilderProvider
{
    @Override
    public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier) {
        return new PKCS12MacCalculatorBuilder() {
            @Override
            public MacCalculator build(final char[] array) throws OperatorCreationException {
                if (!PKCSObjectIdentifiers.id_PBMAC1.equals(algorithmIdentifier.getAlgorithm())) {
                    throw new OperatorCreationException("protection algorithm not PB mac based");
                }
                BcPKCS12PBMac1CalculatorBuilder bcPKCS12PBMac1CalculatorBuilder;
                try {
                    bcPKCS12PBMac1CalculatorBuilder = new BcPKCS12PBMac1CalculatorBuilder(PBMAC1Params.getInstance(algorithmIdentifier.getParameters()));
                }
                catch (final IOException ex) {
                    throw new OperatorCreationException("invalid parameters in protection algorithm: " + ex.getMessage());
                }
                return bcPKCS12PBMac1CalculatorBuilder.build(array);
            }
            
            @Override
            public AlgorithmIdentifier getDigestAlgorithmIdentifier() {
                return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), algorithmIdentifier.getParameters());
            }
        };
    }
}
