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

package org.bouncycastle.cms;

import java.io.IOException;
import java.util.Iterator;
import org.bouncycastle.asn1.ASN1Sequence;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public class PKCS7ProcessableObject implements CMSTypedData
{
    private final ASN1ObjectIdentifier type;
    private final ASN1Encodable structure;
    
    public PKCS7ProcessableObject(final ASN1ObjectIdentifier type, final ASN1Encodable structure) {
        this.type = type;
        this.structure = structure;
    }
    
    @Override
    public ASN1ObjectIdentifier getContentType() {
        return this.type;
    }
    
    @Override
    public void write(final OutputStream outputStream) throws IOException, CMSException {
        if (this.structure instanceof ASN1Sequence) {
            final Iterator<ASN1Encodable> iterator = ASN1Sequence.getInstance(this.structure).iterator();
            while (iterator.hasNext()) {
                outputStream.write(iterator.next().toASN1Primitive().getEncoded("DER"));
            }
        }
        else {
            byte[] encoded;
            int off;
            for (encoded = this.structure.toASN1Primitive().getEncoded("DER"), off = 1; (encoded[off] & 0xFF) > 127; ++off) {}
            ++off;
            outputStream.write(encoded, off, encoded.length - off);
        }
    }
    
    @Override
    public Object getContent() {
        return this.structure;
    }
}
