Esempio n. 1
0
        internal unsafe X509ChainElement(IntPtr pChainElement)
        {
            CAPI.CERT_CHAIN_ELEMENT chainElement = new CAPI.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_ELEMENT)));
            uint cbSize = (uint)Marshal.ReadInt32(pChainElement);

            if (cbSize > Marshal.SizeOf(chainElement))
            {
                cbSize = (uint)Marshal.SizeOf(chainElement);
            }
            X509Utils.memcpy(pChainElement, new IntPtr(&chainElement), cbSize);

            m_certificate = new X509Certificate2(chainElement.pCertContext);
            if (chainElement.pwszExtendedErrorInfo == IntPtr.Zero)
            {
                m_description = String.Empty;
            }
            else
            {
                m_description = Marshal.PtrToStringUni(chainElement.pwszExtendedErrorInfo);
            }

            // We give the user a reference to the array since we'll never access it.
            if (chainElement.dwErrorStatus == 0)
            {
                m_chainStatus = new X509ChainStatus[0]; // empty array
            }
            else
            {
                m_chainStatus = X509Chain.GetChainStatusInformation(chainElement.dwErrorStatus);
            }
        }
        internal unsafe X509ChainElement(IntPtr pChainElement)
        {
            CAPIBase.CERT_CHAIN_ELEMENT structure = new CAPIBase.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPIBase.CERT_CHAIN_ELEMENT)));
            uint size = (uint)Marshal.ReadInt32(pChainElement);

            if (size > Marshal.SizeOf(structure))
            {
                size = (uint)Marshal.SizeOf(structure);
            }
            System.Security.Cryptography.X509Certificates.X509Utils.memcpy(pChainElement, new IntPtr((void *)&structure), size);
            this.m_certificate = new X509Certificate2(structure.pCertContext);
            if (structure.pwszExtendedErrorInfo == IntPtr.Zero)
            {
                this.m_description = string.Empty;
            }
            else
            {
                this.m_description = Marshal.PtrToStringUni(structure.pwszExtendedErrorInfo);
            }
            if (structure.dwErrorStatus == 0)
            {
                this.m_chainStatus = new X509ChainStatus[0];
            }
            else
            {
                this.m_chainStatus = X509Chain.GetChainStatusInformation(structure.dwErrorStatus);
            }
        }