aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/common/secure_auth_context.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp/common/secure_auth_context.cc')
-rw-r--r--src/cpp/common/secure_auth_context.cc38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/cpp/common/secure_auth_context.cc b/src/cpp/common/secure_auth_context.cc
index 1d66dd3d1f..7a2b5afed6 100644
--- a/src/cpp/common/secure_auth_context.cc
+++ b/src/cpp/common/secure_auth_context.cc
@@ -22,19 +22,12 @@
namespace grpc {
-SecureAuthContext::SecureAuthContext(grpc_auth_context* ctx,
- bool take_ownership)
- : ctx_(ctx), take_ownership_(take_ownership) {}
-
-SecureAuthContext::~SecureAuthContext() {
- if (take_ownership_) grpc_auth_context_release(ctx_);
-}
-
std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const {
- if (!ctx_) {
+ if (ctx_ == nullptr) {
return std::vector<grpc::string_ref>();
}
- grpc_auth_property_iterator iter = grpc_auth_context_peer_identity(ctx_);
+ grpc_auth_property_iterator iter =
+ grpc_auth_context_peer_identity(ctx_.get());
std::vector<grpc::string_ref> identity;
const grpc_auth_property* property = nullptr;
while ((property = grpc_auth_property_iterator_next(&iter))) {
@@ -45,20 +38,20 @@ std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const {
}
grpc::string SecureAuthContext::GetPeerIdentityPropertyName() const {
- if (!ctx_) {
+ if (ctx_ == nullptr) {
return "";
}
- const char* name = grpc_auth_context_peer_identity_property_name(ctx_);
+ const char* name = grpc_auth_context_peer_identity_property_name(ctx_.get());
return name == nullptr ? "" : name;
}
std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues(
const grpc::string& name) const {
- if (!ctx_) {
+ if (ctx_ == nullptr) {
return std::vector<grpc::string_ref>();
}
grpc_auth_property_iterator iter =
- grpc_auth_context_find_properties_by_name(ctx_, name.c_str());
+ grpc_auth_context_find_properties_by_name(ctx_.get(), name.c_str());
const grpc_auth_property* property = nullptr;
std::vector<grpc::string_ref> values;
while ((property = grpc_auth_property_iterator_next(&iter))) {
@@ -68,9 +61,9 @@ std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues(
}
AuthPropertyIterator SecureAuthContext::begin() const {
- if (ctx_) {
+ if (ctx_ != nullptr) {
grpc_auth_property_iterator iter =
- grpc_auth_context_property_iterator(ctx_);
+ grpc_auth_context_property_iterator(ctx_.get());
const grpc_auth_property* property =
grpc_auth_property_iterator_next(&iter);
return AuthPropertyIterator(property, &iter);
@@ -85,19 +78,20 @@ AuthPropertyIterator SecureAuthContext::end() const {
void SecureAuthContext::AddProperty(const grpc::string& key,
const grpc::string_ref& value) {
- if (!ctx_) return;
- grpc_auth_context_add_property(ctx_, key.c_str(), value.data(), value.size());
+ if (ctx_ == nullptr) return;
+ grpc_auth_context_add_property(ctx_.get(), key.c_str(), value.data(),
+ value.size());
}
bool SecureAuthContext::SetPeerIdentityPropertyName(const grpc::string& name) {
- if (!ctx_) return false;
- return grpc_auth_context_set_peer_identity_property_name(ctx_,
+ if (ctx_ == nullptr) return false;
+ return grpc_auth_context_set_peer_identity_property_name(ctx_.get(),
name.c_str()) != 0;
}
bool SecureAuthContext::IsPeerAuthenticated() const {
- if (!ctx_) return false;
- return grpc_auth_context_peer_is_authenticated(ctx_) != 0;
+ if (ctx_ == nullptr) return false;
+ return grpc_auth_context_peer_is_authenticated(ctx_.get()) != 0;
}
} // namespace grpc