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