// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/exception/SmartCardException.java
// public class SmartCardException extends Exception {
// 
//     public SmartCardException(String s, Throwable t) {
//         super(s, t);
//     }
// }
// 
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/support/ExceptionSupport.java
// public class ExceptionSupport {
// 
//     private static ResourceBundle bundle = null;
// 
//     public static String getValue(final String key) {
//         if (bundle == null) {
//             Locale locale = new Locale("tr", "TR");
//             bundle = ResourceBundle.getBundle("exception/SmartCardExceptions", locale);
//         }
//         return bundle.getString(key);
//     }
//     
// }


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import tr.gov.turkiye.esign.exception.SmartCardException;
import tr.gov.turkiye.esign.support.ExceptionSupport;
      type identifier and the content itself
     * @param content the bytes of content to be signed.
     * @return DERSequence instance
     */
    private ASN1Encodable getContentInfo(byte[] content) {
        final ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(ObjectID.pkcs7_data);
        DEROctetString ds = new DEROctetString(content);
        DERTaggedObject to = new DERTaggedObject(true, 0, ds);
        v.add(to);
        DERSequence ddd = new DERSequence(v);
        return ddd;
    }

    /**
     * collection of certificates
     * @return DERSet instance
     * @throws SmartCardException 
     */
    private ASN1Encodable getCertificates() throws SmartCardException {
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (Certificate cert : certs) {
            try {
                byte[] encodedCertificate = cert.getEncoded();
                ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(encodedCertificate));
                ASN1Primitive dob = tempstream.readObject();
                v.add(dob);
            }catch (CertificateEncodingException ex) {
                throw new SmartCardException(ExceptionSupport.getValue("CertificateEncodingException"), ex);
            }catch (IOException ex) {
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/exception/SmartCardException.java
// public class SmartCardException extends Exception {
// 
//     public SmartCardException(String s, Throwable t) {
//         super(s, t);
//     }
// }
// 
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/support/ExceptionSupport.java
// public class ExceptionSupport {
// 
//     private static ResourceBundle bundle = null;
// 
//     public static String getValue(final String key) {
//         if (bundle == null) {
//             Locale locale = new Locale("tr", "TR");
//             bundle = ResourceBundle.getBundle("exception/SmartCardExceptions", locale);
//         }
//         return bundle.getString(key);
//     }
//     
// }


// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/cms/SignedData.java
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import tr.gov.turkiye.esign.exception.SmartCardException;
import tr.gov.turkiye.esign.support.ExceptionSupport;

      type identifier and the content itself
     * @param content the bytes of content to be signed.
     * @return DERSequence instance
     */
    private ASN1Encodable getContentInfo(byte[] content) {
        final ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(ObjectID.pkcs7_data);
        DEROctetString ds = new DEROctetString(content);
        DERTaggedObject to = new DERTaggedObject(true, 0, ds);
        v.add(to);
        DERSequence ddd = new DERSequence(v);
        return ddd;
    }

    /**
     * collection of certificates
     * @return DERSet instance
     * @throws SmartCardException 
     */
    private ASN1Encodable getCertificates() throws SmartCardException {
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (Certificate cert : certs) {
            try {
                byte[] encodedCertificate = cert.getEncoded();
                ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(encodedCertificate));
                ASN1Primitive dob = tempstream.readObject();
                v.add(dob);
            }catch (CertificateEncodingException ex) {
                throw new SmartCardException(ExceptionSupport.getValue("CertificateEncodingException"), ex);
            }catch (IOException ex) {
                throw new SmartCardException(ExceptionSupport.getValue("IOException"), ex);