3 * Copyright 2018 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H
20 #define GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H
22 #include <grpc/support/port_platform.h>
24 #include <grpc/slice.h>
25 #include <grpc/slice_buffer.h>
26 #include <grpc/support/alloc.h>
27 #include <grpc/support/log.h>
29 #include "src/proto/grpc/gcp/transport_security_common.upb.h"
31 // C struct coresponding to protobuf message RpcProtocolVersions.Version
32 typedef struct _grpc_gcp_RpcProtocolVersions_Version {
35 } grpc_gcp_rpc_protocol_versions_version;
37 // C struct coresponding to protobuf message RpcProtocolVersions
38 typedef struct _grpc_gcp_RpcProtocolVersions {
39 grpc_gcp_rpc_protocol_versions_version max_rpc_version;
40 grpc_gcp_rpc_protocol_versions_version min_rpc_version;
41 } grpc_gcp_rpc_protocol_versions;
44 * This method sets the value for max_rpc_versions field of rpc protocol
47 * - versions: an rpc protocol version instance.
48 * - max_major: a major version of maximum supported RPC version.
49 * - max_minor: a minor version of maximum supported RPC version.
51 * The method returns true on success and false otherwise.
53 bool grpc_gcp_rpc_protocol_versions_set_max(
54 grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major,
58 * This method sets the value for min_rpc_versions field of rpc protocol
61 * - versions: an rpc protocol version instance.
62 * - min_major: a major version of minimum supported RPC version.
63 * - min_minor: a minor version of minimum supported RPC version.
65 * The method returns true on success and false otherwise.
67 bool grpc_gcp_rpc_protocol_versions_set_min(
68 grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major,
72 * This method serializes an rpc protocol version and returns serialized rpc
73 * versions in grpc slice.
75 * - versions: an rpc protocol versions instance.
76 * - slice: grpc slice where the serialized result will be written.
78 * The method returns true on success and false otherwise.
80 bool grpc_gcp_rpc_protocol_versions_encode(
81 const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice);
84 * This method serializes an rpc protocol version and returns serialized rpc
85 * versions in grpc slice.
87 * - versions: an rpc protocol versions instance.
89 * - slice: grpc slice where the serialized result will be written.
91 * The method returns true on success and false otherwise.
93 bool grpc_gcp_rpc_protocol_versions_encode(
94 const grpc_gcp_RpcProtocolVersions* versions, upb_arena* arena,
98 * This method de-serializes input in grpc slice form and stores the result
99 * in rpc protocol versions.
101 * - slice: a data stream containing a serialized rpc protocol version.
102 * - versions: an rpc protocol version instance used to hold de-serialized
105 * The method returns true on success and false otherwise.
107 bool grpc_gcp_rpc_protocol_versions_decode(
108 const grpc_slice& slice, grpc_gcp_rpc_protocol_versions* versions);
111 * Assigns value of upb RpcProtocolVersions to grpc_gcp_rpc_protocol_versions.
113 void grpc_gcp_rpc_protocol_versions_assign_from_upb(
114 grpc_gcp_rpc_protocol_versions* versions,
115 const grpc_gcp_RpcProtocolVersions* value);
118 * Assigns value of struct grpc_gcp_rpc_protocol_versions to
119 * RpcProtocolVersions.
121 void grpc_gcp_RpcProtocolVersions_assign_from_struct(
122 grpc_gcp_RpcProtocolVersions* versions, upb_arena* arena,
123 const grpc_gcp_rpc_protocol_versions* value);
126 * This method performs a deep copy operation on rpc protocol versions
129 * - src: rpc protocol versions instance that needs to be copied.
130 * - dst: rpc protocol versions instance that stores the copied result.
132 * The method returns true on success and false otherwise.
134 bool grpc_gcp_rpc_protocol_versions_copy(
135 const grpc_gcp_rpc_protocol_versions* src,
136 grpc_gcp_rpc_protocol_versions* dst);
139 * This method performs a version check between local and peer rpc protocol
142 * - local_versions: local rpc protocol versions instance.
143 * - peer_versions: peer rpc protocol versions instance.
144 * - highest_common_version: an output parameter that will store the highest
145 * common rpc protocol version both parties agreed on.
147 * The method returns true if the check passes which means both parties agreed
148 * on a common rpc protocol to use, and false otherwise.
150 bool grpc_gcp_rpc_protocol_versions_check(
151 const grpc_gcp_rpc_protocol_versions* local_versions,
152 const grpc_gcp_rpc_protocol_versions* peer_versions,
153 grpc_gcp_rpc_protocol_versions_version* highest_common_version);
155 namespace grpc_core {
159 * Exposed for testing only.
160 * The method returns 0 if v1 = v2,
161 * returns 1 if v1 > v2,
162 * returns -1 if v1 < v2.
164 int grpc_gcp_rpc_protocol_version_compare(
165 const grpc_gcp_rpc_protocol_versions_version* v1,
166 const grpc_gcp_rpc_protocol_versions_version* v2);
168 } // namespace internal
169 } // namespace grpc_core
171 #endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H */