Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / src / cpp / common / auth_property_iterator.cc
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
19 #include <grpc/grpc_security.h>
20 #include <grpcpp/security/auth_context.h>
21
22 namespace grpc {
23
24 AuthPropertyIterator::AuthPropertyIterator()
25     : property_(nullptr), ctx_(nullptr), index_(0), name_(nullptr) {}
26
27 AuthPropertyIterator::AuthPropertyIterator(
28     const grpc_auth_property* property, const grpc_auth_property_iterator* iter)
29     : property_(property),
30       ctx_(iter->ctx),
31       index_(iter->index),
32       name_(iter->name) {}
33
34 AuthPropertyIterator::~AuthPropertyIterator() {}
35
36 AuthPropertyIterator& AuthPropertyIterator::operator++() {
37   grpc_auth_property_iterator iter = {ctx_, index_, name_};
38   property_ = grpc_auth_property_iterator_next(&iter);
39   ctx_ = iter.ctx;
40   index_ = iter.index;
41   name_ = iter.name;
42   return *this;
43 }
44
45 AuthPropertyIterator AuthPropertyIterator::operator++(int) {
46   AuthPropertyIterator tmp(*this);
47   operator++();
48   return tmp;
49 }
50
51 bool AuthPropertyIterator::operator==(const AuthPropertyIterator& rhs) const {
52   if (property_ == nullptr || rhs.property_ == nullptr) {
53     return property_ == rhs.property_;
54   } else {
55     return index_ == rhs.index_;
56   }
57 }
58
59 bool AuthPropertyIterator::operator!=(const AuthPropertyIterator& rhs) const {
60   return !operator==(rhs);
61 }
62
63 AuthProperty AuthPropertyIterator::operator*() {
64   return std::pair<grpc::string_ref, grpc::string_ref>(
65       property_->name,
66       grpc::string_ref(property_->value, property_->value_length));
67 }
68
69 }  // namespace grpc