public SafeIpcCredential(IpcCredentialType typeIn, object credDataIn) { ipcCredential = new IpcCredential(); ipcCredential.type = typeIn; if (null != credDataIn) { switch (typeIn) { case IpcCredentialType.SymmetricKey: SymmetricKeyCredential symmKey = (SymmetricKeyCredential)credDataIn; ipcCredential.credData = Marshal.AllocHGlobal(Marshal.SizeOf(symmKey)); Marshal.StructureToPtr(symmKey, ipcCredential.credData, false); break; case IpcCredentialType.OAuth2: IpcOAuth2CallbackInfo oauth2Key = (IpcOAuth2CallbackInfo)credDataIn; oAuth2CallbackInfo = GCHandle.Alloc(oauth2Key); ipcCredential.credData = Marshal.AllocHGlobal(Marshal.SizeOf(oauth2Key)); Marshal.StructureToPtr((IpcOAuth2CallbackInfo)oAuth2CallbackInfo.Target, ipcCredential.credData, false); break; case IpcCredentialType.X509Certificate: ipcCredential.credData = (IntPtr)credDataIn; break; default: credData = IntPtr.Zero; throw new NotImplementedException(); } } }
internal void Dispose() { if (IntPtr.Zero != pcCredential) { IpcCredential cred = new IpcCredential(); Marshal.PtrToStructure(pcCredential, cred); pcCredential = IntPtr.Zero; cred.Dispose(); } }
internal IpcPromptContext(IntPtr wndParent, IpcCredential credential, WaitHandle cancelEvent) : this() { hWndParent = wndParent; hCancelEvent = (cancelEvent != null) ? cancelEvent.SafeWaitHandle : new SafeWaitHandle(IntPtr.Zero, true); if (null != credential) { pcCredential = Marshal.AllocHGlobal(Marshal.SizeOf(credential)); Marshal.StructureToPtr(credential, pcCredential, false); } else { pcCredential = IntPtr.Zero; } }
public IpcPromptContext(IntPtr wndParent, IpcCredential credential, IntPtr cancelEvent) : this() { hWndParent = wndParent; hCancelEvent = cancelEvent; if (null != credential) { pcCredential = Marshal.AllocHGlobal(Marshal.SizeOf(credential)); Marshal.StructureToPtr(credential, pcCredential, false); } else { pcCredential = IntPtr.Zero; } }
protected void Dispose(bool disposing) { if (ipcCredential != null) { if (ipcCredential.credData != IntPtr.Zero) { if (ipcCredential.type != IpcCredentialType.X509Certificate) { Marshal.FreeHGlobal(ipcCredential.credData); } ipcCredential.credData = IntPtr.Zero; } ipcCredential = null; } if (oAuth2CallbackInfo != null && oAuth2CallbackInfo.IsAllocated) { oAuth2CallbackInfo.Free(); } }
public SafeIpcPromptContext(IntPtr wndParent, IpcCredential credential, IntPtr cancelEvent) { internalClass = new IpcPromptContext(wndParent, credential, cancelEvent); }