// Path: src/main/java/Diadoc/Api/sign/GOSTSignInfoProvider.java
// public class GOSTSignInfoProvider {
//     private GOSTSignType gostSignType;
// 
//     public GOSTSignInfoProvider(X509Certificate certificate) {
//         gostSignType = getGOSTType(certificate);
//     }
// 
//     public Signature getSignatureInstance() {
//         try {
//             if (gostSignType == GOSTSignType.GOST2001) {
//                 return Signature.getInstance(JCP.GOST_EL_SIGN_NAME);
//             }
//             if (gostSignType == GOSTSignType.GOST2012) {
//                 return Signature.getInstance(JCP.GOST_SIGN_2012_256_NAME);
//             }
//         } catch (NoSuchAlgorithmException ignored) {
//         }
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     public String getDigestOID() {
//         if (gostSignType == GOSTSignType.GOST2001) {
//             return JCP.GOST_DIGEST_OID;
//         }
//         if (gostSignType == GOSTSignType.GOST2012) {
//             return JCP.GOST_DIGEST_2012_256_OID;
//         }
// 
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     public String getSignOID() {
//         if (gostSignType == GOSTSignType.GOST2001) {
//             return JCP.GOST_EL_KEY_OID;
//         }
//         if (gostSignType == GOSTSignType.GOST2012) {
//             return JCP.GOST_PARAMS_SIG_2012_256_KEY_OID;
//         }
// 
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     private GOSTSignType getGOSTType(X509Certificate cert) {
//         if (cert.getSigAlgOID().equals("1.2.643.2.2.3")) {
//             return GOSTSignType.GOST2001;
//         }
//         if (cert.getSigAlgOID().equals("1.2.643.7.1.1.3.2")) {
//             return GOSTSignType.GOST2012;
//         }
// 
//         throw new IllegalArgumentException(String.format("OID %s not supported", cert.getSigAlgOID()));
//     }
// }


import Diadoc.Api.sign.GOSTSignInfoProvider;
import com.objsys.asn1j.runtime.*;
import org.apache.commons.codec.binary.Hex;
import ru.CryptoPro.JCP.ASN.CryptographicMessageSyntax.*;
import ru.CryptoPro.JCP.ASN.PKIX1Explicit88.CertificateSerialNumber;
import ru.CryptoPro.JCP.ASN.PKIX1Explicit88.Name;
import ru.CryptoPro.JCP.params.OID;
import java.io.ByteArrayInputStream;
import java.security.MessageDigest;
import java.security.Signature;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
package Diadoc.Api;



public class CertificateHelper {

    private static final String STR_CMS_OID_DATA = "1.2.840.113549.1.7.1";
    private static final String STR_CMS_OID_SIGNED = "1.2.840.113549.1.7.2";

    public static byte[] createCMS(
            byte[] buffer,
            byte[] sign,
            Certificate cert,
            boolean detached,
// Path: src/main/java/Diadoc/Api/sign/GOSTSignInfoProvider.java
// public class GOSTSignInfoProvider {
//     private GOSTSignType gostSignType;
// 
//     public GOSTSignInfoProvider(X509Certificate certificate) {
//         gostSignType = getGOSTType(certificate);
//     }
// 
//     public Signature getSignatureInstance() {
//         try {
//             if (gostSignType == GOSTSignType.GOST2001) {
//                 return Signature.getInstance(JCP.GOST_EL_SIGN_NAME);
//             }
//             if (gostSignType == GOSTSignType.GOST2012) {
//                 return Signature.getInstance(JCP.GOST_SIGN_2012_256_NAME);
//             }
//         } catch (NoSuchAlgorithmException ignored) {
//         }
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     public String getDigestOID() {
//         if (gostSignType == GOSTSignType.GOST2001) {
//             return JCP.GOST_DIGEST_OID;
//         }
//         if (gostSignType == GOSTSignType.GOST2012) {
//             return JCP.GOST_DIGEST_2012_256_OID;
//         }
// 
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     public String getSignOID() {
//         if (gostSignType == GOSTSignType.GOST2001) {
//             return JCP.GOST_EL_KEY_OID;
//         }
//         if (gostSignType == GOSTSignType.GOST2012) {
//             return JCP.GOST_PARAMS_SIG_2012_256_KEY_OID;
//         }
// 
//         throw new IllegalStateException("Invalid gostSignType");
//     }
// 
//     private GOSTSignType getGOSTType(X509Certificate cert) {
//         if (cert.getSigAlgOID().equals("1.2.643.2.2.3")) {
//             return GOSTSignType.GOST2001;
//         }
//         if (cert.getSigAlgOID().equals("1.2.643.7.1.1.3.2")) {
//             return GOSTSignType.GOST2012;
//         }
// 
//         throw new IllegalArgumentException(String.format("OID %s not supported", cert.getSigAlgOID()));
//     }
// }


// Path: src/main/java/Diadoc/Api/CertificateHelper.java
import Diadoc.Api.sign.GOSTSignInfoProvider;
import com.objsys.asn1j.runtime.*;
import org.apache.commons.codec.binary.Hex;
import ru.CryptoPro.JCP.ASN.CryptographicMessageSyntax.*;
import ru.CryptoPro.JCP.ASN.PKIX1Explicit88.CertificateSerialNumber;
import ru.CryptoPro.JCP.ASN.PKIX1Explicit88.Name;
import ru.CryptoPro.JCP.params.OID;
import java.io.ByteArrayInputStream;
import java.security.MessageDigest;
import java.security.Signature;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

package Diadoc.Api;



public class CertificateHelper {

    private static final String STR_CMS_OID_DATA = "1.2.840.113549.1.7.1";
    private static final String STR_CMS_OID_SIGNED = "1.2.840.113549.1.7.2";

    public static byte[] createCMS(
            byte[] buffer,
            byte[] sign,
            Certificate cert,
            boolean detached,
            GOSTSignInfoProvider gostSignInfoProvider) throws Exception {