Esempio n. 1
0
        internal static CRYPT_OID_INFO[] EnumerateOidInformation(OidGroup group)
        {
            // This list is passed through to the callbacks as a GCHandle, so if the type of this object is
            // changed, the type expected in OidEnumerationCallback must also be changed.
            List<CRYPT_OID_INFO> oidInformation = new List<CRYPT_OID_INFO>();

            GCHandle oidInformationHandle = new GCHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // Get a handle to the OID information list so that we can pass it into the callback function
                oidInformationHandle = GCHandle.Alloc(oidInformation, GCHandleType.Normal);

                if (!UseWin2k3OidStructures)
                {
                    CryptEnumOidInfoCallback callback = new CryptEnumOidInfoCallback(OidEnumerationCallback);

                    UnsafeNativeMethods.CryptEnumOIDInfo(group,
                                                         0,
                                                         GCHandle.ToIntPtr(oidInformationHandle),
                                                         callback);

                    // Make sure we don't GC the callback delegate before we're done enumerating
                    GC.KeepAlive(callback);
                }
                else
                {
                    CryptEnumOidInfoCallbackWin2k3 callback = new CryptEnumOidInfoCallbackWin2k3(OidEnumerationCallbackWin2k3);

                    UnsafeNativeMethods.CryptEnumOIDInfoWin2k3(group,
                                                               0,
                                                               GCHandle.ToIntPtr(oidInformationHandle),
                                                               callback);

                    // Make sure we don't GC the callback delegate before we're done enumerating
                    GC.KeepAlive(callback);
                }
            }
            finally
            {
                if (oidInformationHandle.IsAllocated)
                {
                    oidInformationHandle.Free();
                }
            }

            return oidInformation.ToArray();
        }
Esempio n. 2
0
 internal static extern bool CryptEnumOIDInfoWin2k3(OidGroup dwGroupId,
                                                    int dwFlags,
                                                    IntPtr pvArg,
                                                    CryptEnumOidInfoCallbackWin2k3 pfnEnumOIDInfo);
Esempio n. 3
0
 internal static extern bool CryptEnumOIDInfoWin2k3(OidGroup dwGroupId,
                                                    int dwFlags,
                                                    IntPtr pvArg,
                                                    CryptEnumOidInfoCallbackWin2k3 pfnEnumOIDInfo);
Esempio n. 4
0
        internal static CRYPT_OID_INFO[] EnumerateOidInformation(OidGroup group)
        {
            // This list is passed through to the callbacks as a GCHandle, so if the type of this object is
            // changed, the type expected in OidEnumerationCallback must also be changed.
            List<CRYPT_OID_INFO> oidInformation = new List<CRYPT_OID_INFO>();

            GCHandle oidInformationHandle = new GCHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // Get a handle to the OID information list so that we can pass it into the callback function
                oidInformationHandle = GCHandle.Alloc(oidInformation, GCHandleType.Normal);

                if (!UseWin2k3OidStructures)
                {
                    CryptEnumOidInfoCallback callback = new CryptEnumOidInfoCallback(OidEnumerationCallback);

                    UnsafeNativeMethods.CryptEnumOIDInfo(group,
                                                         0,
                                                         GCHandle.ToIntPtr(oidInformationHandle),
                                                         callback);

                    // Make sure we don't GC the callback delegate before we're done enumerating
                    GC.KeepAlive(callback);
                }
                else
                {
                    CryptEnumOidInfoCallbackWin2k3 callback = new CryptEnumOidInfoCallbackWin2k3(OidEnumerationCallbackWin2k3);

                    UnsafeNativeMethods.CryptEnumOIDInfoWin2k3(group,
                                                               0,
                                                               GCHandle.ToIntPtr(oidInformationHandle),
                                                               callback);

                    // Make sure we don't GC the callback delegate before we're done enumerating
                    GC.KeepAlive(callback);
                }
            }
            finally
            {
                if (oidInformationHandle.IsAllocated)
                {
                    oidInformationHandle.Free();
                }
            }

            return oidInformation.ToArray();
        }