• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H
20 #define GRPC_SRC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H
21 
22 #include <grpc/slice.h>
23 #include <grpc/slice_buffer.h>
24 #include <grpc/support/alloc.h>
25 #include <grpc/support/port_platform.h>
26 
27 #include "src/core/util/crash.h"
28 #include "src/proto/grpc/gcp/transport_security_common.upb.h"
29 
30 // C struct corresponding to protobuf message RpcProtocolVersions.Version
31 typedef struct _grpc_gcp_RpcProtocolVersions_Version {
32   uint32_t major;
33   uint32_t minor;
34 } grpc_gcp_rpc_protocol_versions_version;
35 
36 // C struct corresponding to protobuf message RpcProtocolVersions
37 typedef struct _grpc_gcp_RpcProtocolVersions {
38   grpc_gcp_rpc_protocol_versions_version max_rpc_version;
39   grpc_gcp_rpc_protocol_versions_version min_rpc_version;
40 } grpc_gcp_rpc_protocol_versions;
41 
42 ///
43 /// This method sets the value for max_rpc_versions field of rpc protocol
44 /// versions.
45 ///
46 ///- versions: an rpc protocol version instance.
47 ///- max_major: a major version of maximum supported RPC version.
48 ///- max_minor: a minor version of maximum supported RPC version.
49 ///
50 /// The method returns true on success and false otherwise.
51 ///
52 bool grpc_gcp_rpc_protocol_versions_set_max(
53     grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major,
54     uint32_t max_minor);
55 
56 ///
57 /// This method sets the value for min_rpc_versions field of rpc protocol
58 /// versions.
59 ///
60 ///- versions: an rpc protocol version instance.
61 ///- min_major: a major version of minimum supported RPC version.
62 ///- min_minor: a minor version of minimum supported RPC version.
63 ///
64 /// The method returns true on success and false otherwise.
65 ///
66 bool grpc_gcp_rpc_protocol_versions_set_min(
67     grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major,
68     uint32_t min_minor);
69 
70 ///
71 /// This method serializes an rpc protocol version and returns serialized rpc
72 /// versions in grpc slice.
73 ///
74 ///- versions: an rpc protocol versions instance.
75 ///- slice: grpc slice where the serialized result will be written.
76 ///
77 /// The method returns true on success and false otherwise.
78 ///
79 bool grpc_gcp_rpc_protocol_versions_encode(
80     const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice);
81 
82 ///
83 /// This method serializes an rpc protocol version and returns serialized rpc
84 /// versions in grpc slice.
85 ///
86 ///- versions: an rpc protocol versions instance.
87 ///- arena: upb arena.
88 ///- slice: grpc slice where the serialized result will be written.
89 ///
90 /// The method returns true on success and false otherwise.
91 ///
92 bool grpc_gcp_rpc_protocol_versions_encode(
93     const grpc_gcp_RpcProtocolVersions* versions, upb_Arena* arena,
94     grpc_slice* slice);
95 
96 ///
97 /// This method de-serializes input in grpc slice form and stores the result
98 /// in rpc protocol versions.
99 ///
100 ///- slice: a data stream containing a serialized rpc protocol version.
101 ///- versions: an rpc protocol version instance used to hold de-serialized
102 ///  result.
103 ///
104 /// The method returns true on success and false otherwise.
105 ///
106 bool grpc_gcp_rpc_protocol_versions_decode(
107     const grpc_slice& slice, grpc_gcp_rpc_protocol_versions* versions);
108 
109 ///
110 /// Assigns value of upb RpcProtocolVersions to grpc_gcp_rpc_protocol_versions.
111 ///
112 void grpc_gcp_rpc_protocol_versions_assign_from_upb(
113     grpc_gcp_rpc_protocol_versions* versions,
114     const grpc_gcp_RpcProtocolVersions* value);
115 
116 ///
117 /// Assigns value of struct grpc_gcp_rpc_protocol_versions to
118 /// RpcProtocolVersions.
119 ///
120 void grpc_gcp_RpcProtocolVersions_assign_from_struct(
121     grpc_gcp_RpcProtocolVersions* versions, upb_Arena* arena,
122     const grpc_gcp_rpc_protocol_versions* value);
123 
124 ///
125 /// This method performs a deep copy operation on rpc protocol versions
126 /// instance.
127 ///
128 ///- src: rpc protocol versions instance that needs to be copied.
129 ///- dst: rpc protocol versions instance that stores the copied result.
130 ///
131 /// The method returns true on success and false otherwise.
132 ///
133 bool grpc_gcp_rpc_protocol_versions_copy(
134     const grpc_gcp_rpc_protocol_versions* src,
135     grpc_gcp_rpc_protocol_versions* dst);
136 
137 ///
138 /// This method performs a version check between local and peer rpc protocol
139 /// versions.
140 ///
141 ///- local_versions: local rpc protocol versions instance.
142 ///- peer_versions: peer rpc protocol versions instance.
143 ///- highest_common_version: an output parameter that will store the highest
144 ///  common rpc protocol version both parties agreed on.
145 ///
146 /// The method returns true if the check passes which means both parties agreed
147 /// on a common rpc protocol to use, and false otherwise.
148 ///
149 bool grpc_gcp_rpc_protocol_versions_check(
150     const grpc_gcp_rpc_protocol_versions* local_versions,
151     const grpc_gcp_rpc_protocol_versions* peer_versions,
152     grpc_gcp_rpc_protocol_versions_version* highest_common_version);
153 
154 namespace grpc_core {
155 namespace internal {
156 
157 ///
158 /// Exposed for testing only.
159 /// The method returns 0 if v1 = v2,
160 ///           returns 1 if v1 > v2,
161 ///           returns -1 if v1 < v2.
162 ///
163 int grpc_gcp_rpc_protocol_version_compare(
164     const grpc_gcp_rpc_protocol_versions_version* v1,
165     const grpc_gcp_rpc_protocol_versions_version* v2);
166 
167 }  // namespace internal
168 }  // namespace grpc_core
169 
170 #endif  // GRPC_SRC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H
171