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

package org.bouncycastle.cms;

import java.util.Enumeration;
import org.bouncycastle.asn1.cms.CMSAlgorithmProtection;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.cms.Time;
import java.util.Date;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cms.CMSAttributes;
import java.util.Map;
import org.bouncycastle.asn1.cms.AttributeTable;
import java.util.Hashtable;

public class DefaultSignedAttributeTableGenerator implements CMSAttributeTableGenerator
{
    private final Hashtable table;
    
    public DefaultSignedAttributeTableGenerator() {
        this.table = new Hashtable();
    }
    
    public DefaultSignedAttributeTableGenerator(final AttributeTable attributeTable) {
        if (attributeTable != null) {
            this.table = attributeTable.toHashtable();
        }
        else {
            this.table = new Hashtable();
        }
    }
    
    protected Hashtable createStandardAttributeTable(final Map map) {
        final Hashtable copyHashTable = copyHashTable(this.table);
        if (!copyHashTable.containsKey(CMSAttributes.contentType)) {
            final ASN1ObjectIdentifier instance = ASN1ObjectIdentifier.getInstance(map.get("contentType"));
            if (instance != null) {
                final Attribute value = new Attribute(CMSAttributes.contentType, new DERSet(instance));
                copyHashTable.put(value.getAttrType(), value);
            }
        }
        if (!copyHashTable.containsKey(CMSAttributes.signingTime)) {
            final Attribute value2 = new Attribute(CMSAttributes.signingTime, new DERSet(new Time(new Date())));
            copyHashTable.put(value2.getAttrType(), value2);
        }
        if (!copyHashTable.containsKey(CMSAttributes.messageDigest)) {
            final Attribute value3 = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(map.get("digest"))));
            copyHashTable.put(value3.getAttrType(), value3);
        }
        if (!copyHashTable.contains(CMSAttributes.cmsAlgorithmProtect)) {
            final Attribute value4 = new Attribute(CMSAttributes.cmsAlgorithmProtect, new DERSet(new CMSAlgorithmProtection(map.get("digestAlgID"), 1, map.get("signatureAlgID"))));
            copyHashTable.put(value4.getAttrType(), value4);
        }
        return copyHashTable;
    }
    
    @Override
    public AttributeTable getAttributes(final Map map) {
        return new AttributeTable(this.createStandardAttributeTable(map));
    }
    
    private static Hashtable copyHashTable(final Hashtable hashtable) {
        final Hashtable hashtable2 = new Hashtable();
        final Enumeration keys = hashtable.keys();
        while (keys.hasMoreElements()) {
            final Object nextElement = keys.nextElement();
            hashtable2.put(nextElement, hashtable.get(nextElement));
        }
        return hashtable2;
    }
}
