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_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H 20 #define GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <grpc/slice.h> 25 #include <grpc/slice_buffer.h> 26 #include <grpc/support/alloc.h> 27 #include <grpc/support/log.h> 28 29 #include "src/proto/grpc/gcp/transport_security_common.upb.h" 30 31 // C struct coresponding to protobuf message RpcProtocolVersions.Version 32 typedef struct _grpc_gcp_RpcProtocolVersions_Version { 33 uint32_t major; 34 uint32_t minor; 35 } grpc_gcp_rpc_protocol_versions_version; 36 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; 42 43 /** 44 * This method sets the value for max_rpc_versions field of rpc protocol 45 * versions. 46 * 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. 50 * 51 * The method returns true on success and false otherwise. 52 */ 53 bool grpc_gcp_rpc_protocol_versions_set_max( 54 grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major, 55 uint32_t max_minor); 56 57 /** 58 * This method sets the value for min_rpc_versions field of rpc protocol 59 * versions. 60 * 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. 64 * 65 * The method returns true on success and false otherwise. 66 */ 67 bool grpc_gcp_rpc_protocol_versions_set_min( 68 grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major, 69 uint32_t min_minor); 70 71 /** 72 * This method serializes an rpc protocol version and returns serialized rpc 73 * versions in grpc slice. 74 * 75 * - versions: an rpc protocol versions instance. 76 * - slice: grpc slice where the serialized result will be written. 77 * 78 * The method returns true on success and false otherwise. 79 */ 80 bool grpc_gcp_rpc_protocol_versions_encode( 81 const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice); 82 83 /** 84 * This method serializes an rpc protocol version and returns serialized rpc 85 * versions in grpc slice. 86 * 87 * - versions: an rpc protocol versions instance. 88 * - arena: upb arena. 89 * - slice: grpc slice where the serialized result will be written. 90 * 91 * The method returns true on success and false otherwise. 92 */ 93 bool grpc_gcp_rpc_protocol_versions_encode( 94 const grpc_gcp_RpcProtocolVersions* versions, upb_arena* arena, 95 grpc_slice* slice); 96 97 /** 98 * This method de-serializes input in grpc slice form and stores the result 99 * in rpc protocol versions. 100 * 101 * - slice: a data stream containing a serialized rpc protocol version. 102 * - versions: an rpc protocol version instance used to hold de-serialized 103 * result. 104 * 105 * The method returns true on success and false otherwise. 106 */ 107 bool grpc_gcp_rpc_protocol_versions_decode( 108 const grpc_slice& slice, grpc_gcp_rpc_protocol_versions* versions); 109 110 /** 111 * Assigns value of upb RpcProtocolVersions to grpc_gcp_rpc_protocol_versions. 112 */ 113 void grpc_gcp_rpc_protocol_versions_assign_from_upb( 114 grpc_gcp_rpc_protocol_versions* versions, 115 const grpc_gcp_RpcProtocolVersions* value); 116 117 /** 118 * Assigns value of struct grpc_gcp_rpc_protocol_versions to 119 * RpcProtocolVersions. 120 */ 121 void grpc_gcp_RpcProtocolVersions_assign_from_struct( 122 grpc_gcp_RpcProtocolVersions* versions, upb_arena* arena, 123 const grpc_gcp_rpc_protocol_versions* value); 124 125 /** 126 * This method performs a deep copy operation on rpc protocol versions 127 * instance. 128 * 129 * - src: rpc protocol versions instance that needs to be copied. 130 * - dst: rpc protocol versions instance that stores the copied result. 131 * 132 * The method returns true on success and false otherwise. 133 */ 134 bool grpc_gcp_rpc_protocol_versions_copy( 135 const grpc_gcp_rpc_protocol_versions* src, 136 grpc_gcp_rpc_protocol_versions* dst); 137 138 /** 139 * This method performs a version check between local and peer rpc protocol 140 * versions. 141 * 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. 146 * 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. 149 */ 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); 154 155 namespace grpc_core { 156 namespace internal { 157 158 /** 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. 163 */ 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); 167 168 } // namespace internal 169 } // namespace grpc_core 170 171 #endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H */ 172