示例#1
0
        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();
                }
            }
        }
示例#2
0
        public IpcCredential(IpcCredentialType typeIn, object credDataIn)
        {
            type     = typeIn;
            credData = IntPtr.Zero;
            if (null != credDataIn)
            {
                switch (type)
                {
                case IpcCredentialType.SymmetricKey:
                    SymmetricKeyCredential symmKey = (SymmetricKeyCredential)credDataIn;
                    credData = Marshal.AllocHGlobal(Marshal.SizeOf(symmKey));
                    Marshal.StructureToPtr(symmKey, credData, false);
                    break;

                case IpcCredentialType.OAuth2:
                    IpcOAuth2CallbackInfo oath2Key = (IpcOAuth2CallbackInfo)credDataIn;
                    credData = Marshal.AllocHGlobal(Marshal.SizeOf(oath2Key));
                    Marshal.StructureToPtr(oath2Key, credData, false);
                    break;

                case IpcCredentialType.X509Certificate:
                    IntPtr certificateData = (IntPtr)credDataIn;
                    credData = certificateData;
                    break;

                default:
                    credData = IntPtr.Zero;
                    throw new NotImplementedException();
                }
            }
        }