本文整理汇总了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;
}
示例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();
}
}
}
示例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();
}
}
}