1 // 2 // 3 // Copyright 2018 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 19 #ifndef GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H 20 #define GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H 21 22 #include <grpc/credentials.h> 23 #include <grpc/grpc.h> 24 #include <grpc/grpc_security.h> 25 #include <grpc/grpc_security_constants.h> 26 #include <grpc/support/port_platform.h> 27 28 #include "src/core/lib/channel/channel_args.h" 29 #include "src/core/lib/security/credentials/credentials.h" 30 #include "src/core/lib/security/security_connector/security_connector.h" 31 #include "src/core/util/ref_counted_ptr.h" 32 #include "src/core/util/unique_type_name.h" 33 #include "src/core/util/useful.h" 34 35 // Main class for grpc local channel credential. 36 class grpc_local_credentials final : public grpc_channel_credentials { 37 public: 38 explicit grpc_local_credentials(grpc_local_connect_type connect_type); 39 ~grpc_local_credentials() override = default; 40 41 grpc_core::RefCountedPtr<grpc_channel_security_connector> 42 create_security_connector( 43 grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds, 44 const char* target_name, grpc_core::ChannelArgs* args) override; 45 46 grpc_core::UniqueTypeName type() const override; 47 connect_type()48 grpc_local_connect_type connect_type() const { return connect_type_; } 49 50 private: cmp_impl(const grpc_channel_credentials * other)51 int cmp_impl(const grpc_channel_credentials* other) const override { 52 // TODO(yashykt): Check if we can do something better here 53 return grpc_core::QsortCompare( 54 static_cast<const grpc_channel_credentials*>(this), other); 55 } 56 57 grpc_local_connect_type connect_type_; 58 }; 59 60 // Main class for grpc local server credential. 61 class grpc_local_server_credentials final : public grpc_server_credentials { 62 public: 63 explicit grpc_local_server_credentials(grpc_local_connect_type connect_type); 64 ~grpc_local_server_credentials() override = default; 65 66 grpc_core::RefCountedPtr<grpc_server_security_connector> 67 create_security_connector(const grpc_core::ChannelArgs& /* args */) override; 68 69 grpc_core::UniqueTypeName type() const override; 70 connect_type()71 grpc_local_connect_type connect_type() const { return connect_type_; } 72 73 private: 74 grpc_local_connect_type connect_type_; 75 }; 76 77 #endif // GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H 78