xref: /aosp_15_r20/external/grpc-grpc/src/cpp/client/channel_credentials.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2024 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <grpc/support/port_platform.h>
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 #include <grpc/grpc.h>
21 #include <grpc/grpc_security.h>
22 #include <grpcpp/security/credentials.h>
23 #include <grpcpp/support/channel_arguments.h>
24 
25 namespace grpc {
26 
ChannelCredentials(grpc_channel_credentials * c_creds)27 ChannelCredentials::ChannelCredentials(grpc_channel_credentials* c_creds)
28     : c_creds_(c_creds) {}
29 
~ChannelCredentials()30 ChannelCredentials::~ChannelCredentials() {
31   grpc_channel_credentials_release(c_creds_);
32 }
33 
CreateChannelWithInterceptors(const std::string & target,const ChannelArguments & args,std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators)34 std::shared_ptr<Channel> ChannelCredentials::CreateChannelWithInterceptors(
35     const std::string& target, const ChannelArguments& args,
36     std::vector<
37         std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
38         interceptor_creators) {
39   grpc_channel_args channel_args;
40   args.SetChannelArgs(&channel_args);
41   return grpc::CreateChannelInternal(
42       args.GetSslTargetNameOverride(),
43       grpc_channel_create(target.c_str(), c_creds_, &channel_args),
44       std::move(interceptor_creators));
45 }
46 
47 }  // namespace grpc
48