当前位置: 首页>>代码示例>>C#>>正文


C# SafeFreeCredentials.DangerousAddRef方法代码示例

本文整理汇总了C#中SafeFreeCredentials.DangerousAddRef方法的典型用法代码示例。如果您正苦于以下问题:C# SafeFreeCredentials.DangerousAddRef方法的具体用法?C# SafeFreeCredentials.DangerousAddRef怎么用?C# SafeFreeCredentials.DangerousAddRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SafeFreeCredentials的用法示例。


在下文中一共展示了SafeFreeCredentials.DangerousAddRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AcquireCredentialsHandle

 public SafeFreeCredentials AcquireCredentialsHandle(X509Certificate certificate,
     SslProtocols protocols, EncryptionPolicy policy, bool isServer)
 {
     SafeFreeCredentials retVal = new SafeFreeCredentials(certificate, protocols, policy);
     if (null != retVal)
     {
         // Caller does a ref count decrement
         bool ignore = false;
         retVal.DangerousAddRef(ref ignore);
         // TODO (Issue #3362) retVal is not getting released now, need to be fixed.
     }
     return retVal;
 }
开发者ID:fuwei199006,项目名称:corefx,代码行数:13,代码来源:SSPISecureChannelType.cs

示例2: HandshakeInternal

        private SecurityStatus HandshakeInternal(SafeFreeCredentials credential, ref SafeDeleteContext context,
            SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, bool isServer, bool remoteCertRequired)
        {
            Debug.Assert(!credential.IsInvalid);
            bool gotCredReference = false;
            bool gotContextReference = false;
            GCHandle inputHandle = new GCHandle();

            try
            {
                credential.DangerousAddRef(ref gotCredReference);

                if ((null == context) || context.IsInvalid)
                {
                    long options = GetOptions(credential.Protocols);

                    IntPtr contextPtr = Interop.OpenSsl.AllocateSslContext(
                        options,
                        credential.CertHandle,
                        credential.CertKeyHandle,
                        isServer,
                        remoteCertRequired);                 

                    context = new SafeDeleteContext(contextPtr, credential);
                }

                context.DangerousAddRef(ref gotContextReference);
           
                IntPtr inputPtr = IntPtr.Zero, outputPtr = IntPtr.Zero;
                int outputSize;
                bool done;

                if (null == inputBuffer)
                {
                    done = Interop.OpenSsl.DoSslHandshake(context.DangerousGetHandle(), inputPtr, 0, out outputPtr, out outputSize);
                }
                else
                {
                    inputHandle = GCHandle.Alloc(inputBuffer.token, GCHandleType.Pinned);
                    inputPtr = Marshal.UnsafeAddrOfPinnedArrayElement(inputBuffer.token, inputBuffer.offset);
                    done = Interop.OpenSsl.DoSslHandshake(context.DangerousGetHandle(), inputPtr, inputBuffer.size, out outputPtr, out outputSize);
                }           

                outputBuffer.size = outputSize;
                outputBuffer.offset = 0;
                if (outputSize > 0)
                {
                    outputBuffer.token = new byte[outputBuffer.size];
                    Marshal.Copy(outputPtr, outputBuffer.token, 0, outputBuffer.size);
                    Marshal.FreeHGlobal(outputPtr);
                }
                else
                {
                    outputBuffer.token = null;
                }      

                return done ? SecurityStatus.OK : SecurityStatus.ContinueNeeded;
            }
            catch
            {
                return SecurityStatus.InternalError;
            }
            finally
            {
                if (inputHandle.IsAllocated)
                {
                    inputHandle.Free();
                }
                if (gotContextReference)
                {
                    context.DangerousRelease();
                }
                if (gotCredReference)
                {
                    credential.DangerousRelease();
                }
            }
        }
开发者ID:TAdityaAnirudh,项目名称:corefx,代码行数:78,代码来源:SSPISecureChannelType.cs

示例3: HandshakeInternal

        private SecurityStatus HandshakeInternal(SafeFreeCredentials credential, ref SafeDeleteContext context,
            SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, bool isServer, bool remoteCertRequired)
        {
            Debug.Assert(!credential.IsInvalid);
            bool gotCredReference = false;
            bool gotContextReference = false;

            try
            {
                credential.DangerousAddRef(ref gotCredReference);

                if ((null == context) || context.IsInvalid)
                {
                    long options = GetOptions(credential.Protocols);

                    IntPtr contextPtr = Interop.OpenSsl.AllocateSslContext(
                        options,
                        credential.CertHandle,
                        credential.CertKeyHandle,
                        isServer,
                        remoteCertRequired);                 

                    context = new SafeDeleteContext(contextPtr, credential);
                }

                context.DangerousAddRef(ref gotContextReference);
           
                IntPtr inputPtr = IntPtr.Zero, outputPtr = IntPtr.Zero;
                int outputSize;
                bool done;

                if (null == inputBuffer)
                {
                    done = Interop.OpenSsl.DoSslHandshake(context.DangerousGetHandle(), inputPtr, 0, out outputPtr, out outputSize);
                }
                else
                {
                    unsafe
                    {
                        fixed (byte* tokenPtr = inputBuffer.token)
                        {
                            inputPtr = new IntPtr(tokenPtr + inputBuffer.offset);
                            done = Interop.OpenSsl.DoSslHandshake(context.DangerousGetHandle(), inputPtr, inputBuffer.size, out outputPtr, out outputSize);
                        }
                    }
                }

                outputBuffer.size = outputSize;
                outputBuffer.offset = 0;
                if (outputSize > 0)
                {
                    outputBuffer.token = new byte[outputBuffer.size];
                    Marshal.Copy(outputPtr, outputBuffer.token, 0, outputBuffer.size);
                }
                else
                {
                    outputBuffer.token = null;
                }

                if (outputPtr != IntPtr.Zero)
                {
                     Marshal.FreeHGlobal(outputPtr);
                     outputPtr = IntPtr.Zero;
                }

                return done ? SecurityStatus.OK : SecurityStatus.ContinueNeeded;
            }
            catch (Exception ex)
            {
                Debug.Fail("Exception Caught. - " + ex);
                return SecurityStatus.InternalError;             
            }
            finally
            {
                if (gotContextReference)
                {
                    context.DangerousRelease();
                }
                if (gotCredReference)
                {
                    credential.DangerousRelease();
                }
            }
        }
开发者ID:fuwei199006,项目名称:corefx,代码行数:84,代码来源:SSPISecureChannelType.cs


注:本文中的SafeFreeCredentials.DangerousAddRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。