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