internal override CredentialsSafeHandle ToNativeCredentials() { using (var cred1 = channelCredentials.ToNativeCredentials()) using (var cred2 = callCredentials.ToNativeCredentials()) { var nativeComposite = CredentialsSafeHandle.CreateComposite(cred1, cred2); if (nativeComposite.IsInvalid) { throw new ArgumentException("Error creating native composite credentials. Likely, this is because you are trying to compose incompatible credentials."); } return(nativeComposite); } }
// Recursive descent makes managing lifetime of intermediate CredentialSafeHandle instances easier. // In practice, we won't usually see composites from more than two credentials anyway. private CredentialsSafeHandle ToNativeRecursive(int startIndex) { if (startIndex == credentials.Count - 1) { return(credentials[startIndex].ToNativeCredentials()); } using (var cred1 = credentials[startIndex].ToNativeCredentials()) using (var cred2 = ToNativeRecursive(startIndex + 1)) { var nativeComposite = CredentialsSafeHandle.CreateComposite(cred1, cred2); if (nativeComposite.IsInvalid) { throw new ArgumentException("Error creating native composite credentials. Likely, this is because you are trying to compose incompatible credentials."); } return(nativeComposite); } }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 a secure channel. /// </summary> /// <param name="host">The DNS name of IP address of the host.</param> /// <param name="credentials">Optional credentials to create a secure channel.</param> /// <param name="options">Channel options.</param> public Channel(string host, Credentials credentials = null, IEnumerable <ChannelOption> options = null) { using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(options)) { if (credentials != null) { using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials()) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, host, nativeChannelArgs); } } else { this.handle = ChannelSafeHandle.Create(host, nativeChannelArgs); } } this.target = GetOverridenTarget(host, options); }
/// <summary> /// Creates a channel. /// </summary> public Channel(string target, Credentials credentials = null, ChannelArgs channelArgs = null) { using (ChannelArgsSafeHandle nativeChannelArgs = CreateNativeChannelArgs(channelArgs)) { if (credentials != null) { using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials()) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } } else { this.handle = ChannelSafeHandle.Create(target, nativeChannelArgs); } } this.target = GetOverridenTarget(target, channelArgs); }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string target, Credentials credentials, IEnumerable <ChannelOption> options = null) { this.target = Preconditions.CheckNotNull(target, "target"); this.environment = GrpcEnvironment.AddRef(); this.options = options != null ? new List <ChannelOption>(options) : new List <ChannelOption>(); EnsureUserAgentChannelOption(this.options); using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials()) using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options)) { if (nativeCredentials != null) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } else { this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs); } } }
internal override CredentialsSafeHandle ToNativeCredentials() { return(CredentialsSafeHandle.CreateSslCredentials(rootCertificates, keyCertificatePair)); }
internal override CredentialsSafeHandle ToNativeCredentials() { return(CredentialsSafeHandle.CreateSslCredentials(pemRootCerts)); }