couchbase 3.5.1 → 3.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (1166) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/0001-fix-build-for-mingw-w64-ucrt-x86_64-toolchain.patch +40 -0
  4. data/ext/CMakeLists.txt +22 -2
  5. data/ext/cache/extconf_include.rb +3 -3
  6. data/ext/cache/mozilla-ca-bundle.crt +19 -32
  7. data/ext/cache/mozilla-ca-bundle.sha256 +1 -1
  8. data/ext/couchbase/CMakeLists.txt +16 -9
  9. data/ext/couchbase/cmake/0001-fix-build-for-mingw-w64-ucrt-x86_64-toolchain.patch +3 -4
  10. data/ext/couchbase/cmake/CompilerWarnings.cmake +2 -1
  11. data/ext/couchbase/cmake/Packaging.cmake +41 -0
  12. data/ext/couchbase/cmake/Sanitizers.cmake +1 -0
  13. data/ext/couchbase/cmake/VersionInfo.cmake +5 -5
  14. data/ext/couchbase/cmake/build_version.hxx.in +1 -0
  15. data/ext/couchbase/cmake/couchbase-cxx-client.pc.in +10 -0
  16. data/ext/couchbase/cmake/test_boringssl.cxx +1 -1
  17. data/ext/couchbase/cmake/test_openssl.cxx +1 -1
  18. data/ext/couchbase/core/agent.cxx +353 -304
  19. data/ext/couchbase/core/agent.hxx +94 -76
  20. data/ext/couchbase/core/agent_config.cxx +9 -8
  21. data/ext/couchbase/core/agent_config.hxx +7 -7
  22. data/ext/couchbase/core/agent_group.cxx +132 -120
  23. data/ext/couchbase/core/agent_group.hxx +26 -22
  24. data/ext/couchbase/core/agent_group_config.cxx +8 -7
  25. data/ext/couchbase/core/agent_group_config.hxx +6 -6
  26. data/ext/couchbase/core/agent_unit_test_api.hxx +6 -6
  27. data/ext/couchbase/core/analytics_query_options.cxx +21 -21
  28. data/ext/couchbase/core/analytics_query_options.hxx +19 -18
  29. data/ext/couchbase/core/analytics_scan_consistency.hxx +2 -2
  30. data/ext/couchbase/core/bucket.cxx +848 -776
  31. data/ext/couchbase/core/bucket.hxx +151 -139
  32. data/ext/couchbase/core/capella_ca.hxx +20 -19
  33. data/ext/couchbase/core/cluster.cxx +1240 -927
  34. data/ext/couchbase/core/cluster.hxx +254 -167
  35. data/ext/couchbase/core/cluster_agent.cxx +7 -7
  36. data/ext/couchbase/core/cluster_agent.hxx +4 -4
  37. data/ext/couchbase/core/cluster_agent_config.cxx +8 -7
  38. data/ext/couchbase/core/cluster_agent_config.hxx +6 -6
  39. data/ext/couchbase/core/cluster_options.cxx +17 -17
  40. data/ext/couchbase/core/cluster_options.hxx +50 -47
  41. data/ext/couchbase/core/cluster_state.hxx +3 -3
  42. data/ext/couchbase/core/collection_id_cache_entry.hxx +5 -4
  43. data/ext/couchbase/core/collections_component.cxx +372 -329
  44. data/ext/couchbase/core/collections_component.hxx +17 -13
  45. data/ext/couchbase/core/collections_component_unit_test_api.hxx +6 -6
  46. data/ext/couchbase/core/collections_options.hxx +29 -27
  47. data/ext/couchbase/core/config_listener.hxx +3 -3
  48. data/ext/couchbase/core/config_profile.hxx +3 -3
  49. data/ext/couchbase/core/config_profiles.cxx +31 -31
  50. data/ext/couchbase/core/config_profiles.hxx +19 -19
  51. data/ext/couchbase/core/core_sdk_shim.cxx +2 -1
  52. data/ext/couchbase/core/core_sdk_shim.hxx +2 -2
  53. data/ext/couchbase/core/crud_component.cxx +310 -276
  54. data/ext/couchbase/core/crud_component.hxx +21 -15
  55. data/ext/couchbase/core/crud_options.hxx +361 -354
  56. data/ext/couchbase/core/crypto/cbcrypto.cc +732 -627
  57. data/ext/couchbase/core/crypto/cbcrypto.h +12 -3
  58. data/ext/couchbase/core/design_document_namespace.hxx +2 -2
  59. data/ext/couchbase/core/design_document_namespace_fmt.hxx +18 -18
  60. data/ext/couchbase/core/diagnostics.hxx +44 -44
  61. data/ext/couchbase/core/diagnostics_fmt.hxx +76 -76
  62. data/ext/couchbase/core/diagnostics_json.hxx +61 -60
  63. data/ext/couchbase/core/diagntostics_options.hxx +14 -14
  64. data/ext/couchbase/core/dispatcher.cxx +4 -3
  65. data/ext/couchbase/core/dispatcher.hxx +8 -7
  66. data/ext/couchbase/core/document_id.cxx +37 -34
  67. data/ext/couchbase/core/document_id.hxx +87 -86
  68. data/ext/couchbase/core/document_id_fmt.hxx +10 -10
  69. data/ext/couchbase/core/durability_options.hxx +50 -49
  70. data/ext/couchbase/core/error_context/analytics.hxx +18 -18
  71. data/ext/couchbase/core/error_context/analytics_json.hxx +115 -0
  72. data/ext/couchbase/core/error_context/base_error_context.hxx +184 -0
  73. data/ext/couchbase/core/error_context/http.hxx +14 -14
  74. data/ext/couchbase/core/error_context/http_json.hxx +90 -0
  75. data/ext/couchbase/core/error_context/internal_tof_metadata_json.hxx +36 -0
  76. data/ext/couchbase/core/error_context/key_value.cxx +27 -27
  77. data/ext/couchbase/core/error_context/key_value.hxx +41 -38
  78. data/ext/couchbase/core/error_context/key_value_error_context.hxx +235 -0
  79. data/ext/couchbase/core/error_context/key_value_error_map_attribute.hxx +142 -0
  80. data/ext/couchbase/core/error_context/key_value_error_map_info.hxx +139 -0
  81. data/ext/couchbase/core/error_context/key_value_extended_error_info.hxx +86 -0
  82. data/ext/couchbase/core/error_context/key_value_json.hxx +83 -0
  83. data/ext/couchbase/core/error_context/key_value_status_code.hxx +109 -0
  84. data/ext/couchbase/core/error_context/query.hxx +18 -18
  85. data/ext/couchbase/core/error_context/query_error_context.hxx +150 -0
  86. data/ext/couchbase/core/error_context/query_json.hxx +114 -0
  87. data/ext/couchbase/core/error_context/query_public_json.hxx +84 -0
  88. data/ext/couchbase/core/error_context/search.hxx +17 -17
  89. data/ext/couchbase/core/error_context/search_json.hxx +101 -0
  90. data/ext/couchbase/core/error_context/subdocument_error_context.hxx +147 -0
  91. data/ext/couchbase/core/error_context/subdocument_json.hxx +48 -0
  92. data/ext/couchbase/{couchbase → core/error_context}/transaction_error_context.hxx +22 -22
  93. data/ext/couchbase/core/error_context/transaction_op_error_context.hxx +79 -0
  94. data/ext/couchbase/core/error_context/view.hxx +17 -17
  95. data/ext/couchbase/core/fmt/key_value_error_map_attribute.hxx +100 -0
  96. data/ext/couchbase/{couchbase → core}/fmt/key_value_extended_error_info.hxx +20 -20
  97. data/ext/couchbase/core/fmt/key_value_status_code.hxx +269 -0
  98. data/ext/couchbase/core/free_form_http_request.cxx +26 -26
  99. data/ext/couchbase/core/free_form_http_request.hxx +34 -33
  100. data/ext/couchbase/core/impl/analytics.cxx +111 -131
  101. data/ext/couchbase/core/impl/analytics.hxx +5 -7
  102. data/ext/couchbase/core/impl/analytics_error_category.cxx +29 -28
  103. data/ext/couchbase/core/impl/analytics_index_manager.cxx +615 -516
  104. data/ext/couchbase/core/impl/best_effort_retry_strategy.cxx +53 -50
  105. data/ext/couchbase/core/impl/binary_collection.cxx +346 -285
  106. data/ext/couchbase/core/impl/boolean_field_query.cxx +10 -10
  107. data/ext/couchbase/core/impl/boolean_query.cxx +27 -27
  108. data/ext/couchbase/core/impl/bootstrap_state_listener.hxx +6 -6
  109. data/ext/couchbase/core/impl/bucket.cxx +39 -34
  110. data/ext/couchbase/core/impl/bucket_manager.cxx +354 -313
  111. data/ext/couchbase/core/impl/cluster.cxx +430 -325
  112. data/ext/couchbase/core/impl/collection.cxx +1033 -1187
  113. data/ext/couchbase/core/impl/collection_manager.cxx +201 -170
  114. data/ext/couchbase/core/impl/common_error_category.cxx +58 -55
  115. data/ext/couchbase/core/impl/configuration_profiles_registry.cxx +46 -32
  116. data/ext/couchbase/core/impl/conjunction_query.cxx +17 -17
  117. data/ext/couchbase/core/impl/date_range.cxx +24 -20
  118. data/ext/couchbase/core/impl/date_range_facet.cxx +22 -22
  119. data/ext/couchbase/core/impl/date_range_facet_result.cxx +6 -6
  120. data/ext/couchbase/core/impl/date_range_query.cxx +50 -48
  121. data/ext/couchbase/core/impl/diagnostics.cxx +211 -198
  122. data/ext/couchbase/core/impl/diagnostics.hxx +7 -6
  123. data/ext/couchbase/core/impl/disjunction_query.cxx +18 -17
  124. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +92 -75
  125. data/ext/couchbase/core/impl/dns_srv_tracker.hxx +24 -20
  126. data/ext/couchbase/core/impl/doc_id_query.cxx +9 -9
  127. data/ext/couchbase/core/impl/encoded_search_facet.hxx +2 -2
  128. data/ext/couchbase/core/impl/encoded_search_query.hxx +2 -2
  129. data/ext/couchbase/core/impl/encoded_search_sort.hxx +2 -2
  130. data/ext/couchbase/core/impl/error.cxx +171 -0
  131. data/ext/couchbase/core/impl/error.hxx +64 -0
  132. data/ext/couchbase/core/impl/error_context.cxx +56 -0
  133. data/ext/couchbase/core/impl/expiry.cxx +66 -53
  134. data/ext/couchbase/core/impl/fail_fast_retry_strategy.cxx +5 -4
  135. data/ext/couchbase/core/impl/field_level_encryption_error_category.cxx +30 -28
  136. data/ext/couchbase/core/impl/geo_bounding_box_query.cxx +17 -17
  137. data/ext/couchbase/core/impl/geo_distance_query.cxx +14 -14
  138. data/ext/couchbase/core/impl/geo_polygon_query.cxx +17 -17
  139. data/ext/couchbase/core/impl/get_all_replicas.hxx +26 -22
  140. data/ext/couchbase/core/impl/get_any_replica.hxx +25 -23
  141. data/ext/couchbase/core/impl/get_replica.cxx +18 -15
  142. data/ext/couchbase/core/impl/get_replica.hxx +23 -18
  143. data/ext/couchbase/core/impl/internal_date_range_facet_result.cxx +16 -14
  144. data/ext/couchbase/core/impl/internal_date_range_facet_result.hxx +16 -15
  145. data/ext/couchbase/core/impl/internal_error_context.cxx +79 -0
  146. data/ext/couchbase/core/impl/internal_error_context.hxx +52 -0
  147. data/ext/couchbase/core/impl/internal_numeric_range_facet_result.cxx +18 -15
  148. data/ext/couchbase/core/impl/internal_numeric_range_facet_result.hxx +16 -15
  149. data/ext/couchbase/core/impl/internal_scan_result.hxx +7 -7
  150. data/ext/couchbase/core/impl/internal_search_error_context.cxx +25 -22
  151. data/ext/couchbase/core/impl/internal_search_error_context.hxx +32 -31
  152. data/ext/couchbase/core/impl/internal_search_meta_data.cxx +15 -13
  153. data/ext/couchbase/core/impl/internal_search_meta_data.hxx +10 -9
  154. data/ext/couchbase/core/impl/internal_search_result.cxx +30 -22
  155. data/ext/couchbase/core/impl/internal_search_result.hxx +10 -9
  156. data/ext/couchbase/core/impl/internal_search_row.cxx +10 -10
  157. data/ext/couchbase/core/impl/internal_search_row.hxx +16 -16
  158. data/ext/couchbase/core/impl/internal_search_row_location.hxx +2 -2
  159. data/ext/couchbase/core/impl/internal_search_row_locations.cxx +68 -65
  160. data/ext/couchbase/core/impl/internal_search_row_locations.hxx +16 -13
  161. data/ext/couchbase/core/impl/internal_term_facet_result.cxx +16 -14
  162. data/ext/couchbase/core/impl/internal_term_facet_result.hxx +15 -15
  163. data/ext/couchbase/core/impl/key_value_error_category.cxx +73 -72
  164. data/ext/couchbase/core/impl/key_value_error_context.cxx +65 -65
  165. data/ext/couchbase/core/impl/logger.cxx +91 -0
  166. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +32 -29
  167. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +33 -29
  168. data/ext/couchbase/core/impl/lookup_in_replica.cxx +75 -68
  169. data/ext/couchbase/core/impl/lookup_in_replica.hxx +30 -26
  170. data/ext/couchbase/core/impl/management_error_category.cxx +41 -40
  171. data/ext/couchbase/core/impl/match_all_query.cxx +6 -6
  172. data/ext/couchbase/core/impl/match_none_query.cxx +6 -6
  173. data/ext/couchbase/core/impl/match_phrase_query.cxx +13 -13
  174. data/ext/couchbase/core/impl/match_query.cxx +28 -28
  175. data/ext/couchbase/core/impl/network_error_category.cxx +39 -38
  176. data/ext/couchbase/core/impl/numeric_range.cxx +6 -6
  177. data/ext/couchbase/core/impl/numeric_range_facet.cxx +22 -22
  178. data/ext/couchbase/core/impl/numeric_range_facet_result.cxx +6 -6
  179. data/ext/couchbase/core/impl/numeric_range_query.cxx +22 -22
  180. data/ext/couchbase/core/impl/observe_poll.cxx +294 -277
  181. data/ext/couchbase/core/impl/observe_poll.hxx +1 -1
  182. data/ext/couchbase/core/impl/observe_seqno.cxx +21 -18
  183. data/ext/couchbase/core/impl/observe_seqno.hxx +31 -26
  184. data/ext/couchbase/core/impl/phrase_query.cxx +10 -10
  185. data/ext/couchbase/core/impl/prefix_query.cxx +10 -10
  186. data/ext/couchbase/core/impl/query.cxx +163 -154
  187. data/ext/couchbase/core/impl/query.hxx +6 -7
  188. data/ext/couchbase/core/impl/query_error_category.cxx +22 -21
  189. data/ext/couchbase/core/impl/query_error_context.cxx +45 -45
  190. data/ext/couchbase/core/impl/query_index_manager.cxx +488 -408
  191. data/ext/couchbase/core/impl/query_string_query.cxx +7 -7
  192. data/ext/couchbase/core/impl/regexp_query.cxx +10 -10
  193. data/ext/couchbase/core/impl/replica_utils.cxx +66 -0
  194. data/ext/couchbase/core/impl/replica_utils.hxx +48 -0
  195. data/ext/couchbase/core/impl/retry_action.cxx +3 -3
  196. data/ext/couchbase/core/impl/retry_reason.cxx +129 -56
  197. data/ext/couchbase/core/impl/retry_reason.hxx +28 -0
  198. data/ext/couchbase/core/impl/scan_result.cxx +53 -49
  199. data/ext/couchbase/core/impl/scope.cxx +103 -94
  200. data/ext/couchbase/core/impl/search.cxx +139 -130
  201. data/ext/couchbase/core/impl/search.hxx +4 -4
  202. data/ext/couchbase/core/impl/search_error_category.cxx +18 -17
  203. data/ext/couchbase/core/impl/search_index_manager.cxx +492 -390
  204. data/ext/couchbase/core/impl/search_meta_data.cxx +3 -3
  205. data/ext/couchbase/core/impl/search_request.cxx +78 -78
  206. data/ext/couchbase/core/impl/search_result.cxx +5 -5
  207. data/ext/couchbase/core/impl/search_row.cxx +7 -7
  208. data/ext/couchbase/core/impl/search_row_location.cxx +9 -8
  209. data/ext/couchbase/core/impl/search_row_locations.cxx +8 -7
  210. data/ext/couchbase/core/impl/search_sort_field.cxx +53 -53
  211. data/ext/couchbase/core/impl/search_sort_geo_distance.cxx +49 -48
  212. data/ext/couchbase/core/impl/search_sort_id.cxx +10 -10
  213. data/ext/couchbase/core/impl/search_sort_score.cxx +10 -10
  214. data/ext/couchbase/core/impl/streaming_json_lexer_error_category.cxx +70 -68
  215. data/ext/couchbase/core/impl/subdoc/array_add_unique.cxx +6 -6
  216. data/ext/couchbase/core/impl/subdoc/array_append.cxx +6 -6
  217. data/ext/couchbase/core/impl/subdoc/array_insert.cxx +6 -6
  218. data/ext/couchbase/core/impl/subdoc/array_prepend.cxx +6 -6
  219. data/ext/couchbase/core/impl/subdoc/command.hxx +5 -5
  220. data/ext/couchbase/core/impl/subdoc/command_bundle.hxx +11 -11
  221. data/ext/couchbase/core/impl/subdoc/count.cxx +6 -6
  222. data/ext/couchbase/core/impl/subdoc/counter.cxx +6 -6
  223. data/ext/couchbase/core/impl/subdoc/exists.cxx +6 -6
  224. data/ext/couchbase/core/impl/subdoc/get.cxx +6 -6
  225. data/ext/couchbase/core/impl/subdoc/insert.cxx +6 -6
  226. data/ext/couchbase/core/impl/subdoc/join_values.cxx +25 -25
  227. data/ext/couchbase/core/impl/subdoc/lookup_in_macro.cxx +61 -60
  228. data/ext/couchbase/core/impl/subdoc/lookup_in_specs.cxx +9 -9
  229. data/ext/couchbase/core/impl/subdoc/mutate_in_macro.cxx +48 -39
  230. data/ext/couchbase/core/impl/subdoc/mutate_in_specs.cxx +9 -9
  231. data/ext/couchbase/core/impl/subdoc/opcode.hxx +16 -16
  232. data/ext/couchbase/core/impl/subdoc/path_flags.hxx +40 -17
  233. data/ext/couchbase/core/impl/subdoc/remove.cxx +6 -6
  234. data/ext/couchbase/core/impl/subdoc/replace.cxx +6 -6
  235. data/ext/couchbase/core/impl/subdoc/upsert.cxx +6 -6
  236. data/ext/couchbase/core/impl/term_facet.cxx +8 -8
  237. data/ext/couchbase/core/impl/term_facet_result.cxx +6 -6
  238. data/ext/couchbase/core/impl/term_query.cxx +25 -25
  239. data/ext/couchbase/core/impl/term_range_query.cxx +22 -22
  240. data/ext/couchbase/core/impl/transaction_error_category.cxx +21 -20
  241. data/ext/couchbase/core/impl/transaction_get_result.cxx +41 -30
  242. data/ext/couchbase/core/impl/transaction_op_error_category.cxx +55 -56
  243. data/ext/couchbase/core/impl/vector_query.cxx +15 -10
  244. data/ext/couchbase/core/impl/vector_search.cxx +9 -9
  245. data/ext/couchbase/core/impl/view_error_category.cxx +17 -16
  246. data/ext/couchbase/core/impl/wildcard_query.cxx +10 -10
  247. data/ext/couchbase/core/impl/with_legacy_durability.hxx +30 -29
  248. data/ext/couchbase/core/io/dns_client.cxx +257 -232
  249. data/ext/couchbase/core/io/dns_client.hxx +19 -18
  250. data/ext/couchbase/core/io/dns_codec.hxx +156 -154
  251. data/ext/couchbase/core/io/dns_config.cxx +114 -109
  252. data/ext/couchbase/core/io/dns_config.hxx +15 -13
  253. data/ext/couchbase/core/io/dns_message.hxx +365 -342
  254. data/ext/couchbase/core/io/http_command.hxx +155 -134
  255. data/ext/couchbase/core/io/http_context.hxx +5 -5
  256. data/ext/couchbase/core/io/http_message.hxx +75 -71
  257. data/ext/couchbase/core/io/http_parser.cxx +70 -67
  258. data/ext/couchbase/core/io/http_parser.hxx +18 -18
  259. data/ext/couchbase/core/io/http_session.hxx +620 -520
  260. data/ext/couchbase/core/io/http_session_manager.hxx +406 -315
  261. data/ext/couchbase/core/io/http_traits.hxx +7 -0
  262. data/ext/couchbase/core/io/ip_protocol.hxx +3 -3
  263. data/ext/couchbase/core/io/mcbp_command.hxx +298 -278
  264. data/ext/couchbase/core/io/mcbp_context.hxx +7 -6
  265. data/ext/couchbase/core/io/mcbp_message.cxx +8 -8
  266. data/ext/couchbase/core/io/mcbp_message.hxx +19 -19
  267. data/ext/couchbase/core/io/mcbp_parser.cxx +60 -51
  268. data/ext/couchbase/core/io/mcbp_parser.hxx +21 -17
  269. data/ext/couchbase/core/io/mcbp_session.cxx +1769 -1616
  270. data/ext/couchbase/core/io/mcbp_session.hxx +63 -57
  271. data/ext/couchbase/core/io/query_cache.hxx +34 -34
  272. data/ext/couchbase/core/io/retry_context.hxx +45 -45
  273. data/ext/couchbase/core/io/retry_orchestrator.hxx +52 -42
  274. data/ext/couchbase/core/io/streams.hxx +210 -193
  275. data/ext/couchbase/core/json_string.hxx +47 -47
  276. data/ext/couchbase/core/key_value_config.cxx +8 -8
  277. data/ext/couchbase/core/key_value_config.hxx +12 -11
  278. data/ext/couchbase/core/logger/configuration.hxx +35 -35
  279. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +73 -72
  280. data/ext/couchbase/core/logger/custom_rotating_file_sink.hxx +20 -18
  281. data/ext/couchbase/core/logger/level.hxx +9 -1
  282. data/ext/couchbase/core/logger/logger.cxx +279 -252
  283. data/ext/couchbase/core/logger/logger.hxx +110 -58
  284. data/ext/couchbase/core/management/analytics_dataset.hxx +4 -4
  285. data/ext/couchbase/core/management/analytics_index.hxx +4 -4
  286. data/ext/couchbase/core/management/analytics_link_azure_blob_external.cxx +35 -33
  287. data/ext/couchbase/core/management/analytics_link_azure_blob_external.hxx +36 -35
  288. data/ext/couchbase/core/management/analytics_link_azure_blob_external_json.hxx +24 -20
  289. data/ext/couchbase/core/management/analytics_link_couchbase_remote.cxx +66 -65
  290. data/ext/couchbase/core/management/analytics_link_couchbase_remote.hxx +77 -70
  291. data/ext/couchbase/core/management/analytics_link_couchbase_remote_json.hxx +38 -32
  292. data/ext/couchbase/core/management/analytics_link_s3_external.cxx +26 -25
  293. data/ext/couchbase/core/management/analytics_link_s3_external.hxx +30 -30
  294. data/ext/couchbase/core/management/analytics_link_s3_external_json.hxx +18 -16
  295. data/ext/couchbase/core/management/bucket_settings.hxx +109 -91
  296. data/ext/couchbase/core/management/bucket_settings_json.hxx +112 -94
  297. data/ext/couchbase/core/management/design_document.hxx +9 -9
  298. data/ext/couchbase/core/management/eventing_function.hxx +124 -121
  299. data/ext/couchbase/core/management/eventing_function_json.hxx +228 -184
  300. data/ext/couchbase/core/management/eventing_status.hxx +41 -41
  301. data/ext/couchbase/core/management/eventing_status_json.hxx +53 -45
  302. data/ext/couchbase/core/management/rbac.hxx +33 -28
  303. data/ext/couchbase/core/management/rbac_fmt.hxx +21 -21
  304. data/ext/couchbase/core/management/rbac_json.hxx +132 -125
  305. data/ext/couchbase/core/management/search_index.cxx +79 -0
  306. data/ext/couchbase/core/management/search_index.hxx +11 -10
  307. data/ext/couchbase/core/management/search_index_json.hxx +27 -26
  308. data/ext/couchbase/core/mcbp/barrier_frame.hxx +4 -3
  309. data/ext/couchbase/core/mcbp/big_endian.cxx +22 -22
  310. data/ext/couchbase/core/mcbp/buffer_writer.cxx +22 -19
  311. data/ext/couchbase/core/mcbp/buffer_writer.hxx +9 -9
  312. data/ext/couchbase/core/mcbp/codec.cxx +419 -397
  313. data/ext/couchbase/core/mcbp/codec.hxx +14 -12
  314. data/ext/couchbase/core/mcbp/command_code.cxx +48 -48
  315. data/ext/couchbase/core/mcbp/completion_token.hxx +33 -33
  316. data/ext/couchbase/core/mcbp/datatype.hxx +3 -3
  317. data/ext/couchbase/core/mcbp/durability_level.hxx +8 -7
  318. data/ext/couchbase/core/mcbp/durability_level_frame.hxx +3 -2
  319. data/ext/couchbase/core/mcbp/durability_timeout_frame.hxx +4 -3
  320. data/ext/couchbase/core/mcbp/open_tracing_frame.hxx +3 -2
  321. data/ext/couchbase/core/mcbp/operation_consumer.cxx +3 -3
  322. data/ext/couchbase/core/mcbp/operation_consumer.hxx +9 -9
  323. data/ext/couchbase/core/mcbp/operation_queue.cxx +76 -70
  324. data/ext/couchbase/core/mcbp/operation_queue.hxx +18 -17
  325. data/ext/couchbase/core/mcbp/packet.cxx +65 -51
  326. data/ext/couchbase/core/mcbp/packet.hxx +25 -25
  327. data/ext/couchbase/core/mcbp/preserve_expiry_frame.hxx +4 -2
  328. data/ext/couchbase/core/mcbp/queue_callback.hxx +3 -2
  329. data/ext/couchbase/core/mcbp/queue_request.cxx +65 -62
  330. data/ext/couchbase/core/mcbp/queue_request.hxx +54 -52
  331. data/ext/couchbase/core/mcbp/queue_request_connection_info.hxx +3 -3
  332. data/ext/couchbase/core/mcbp/queue_response.hxx +7 -7
  333. data/ext/couchbase/core/mcbp/read_units_frame.hxx +3 -2
  334. data/ext/couchbase/core/mcbp/server_duration.cxx +7 -7
  335. data/ext/couchbase/core/mcbp/server_duration_frame.hxx +3 -2
  336. data/ext/couchbase/core/mcbp/stream_id_frame.hxx +3 -2
  337. data/ext/couchbase/core/mcbp/unsupported_frame.hxx +4 -3
  338. data/ext/couchbase/core/mcbp/user_impersonation_frame.hxx +1 -1
  339. data/ext/couchbase/core/mcbp/write_units_frame.hxx +3 -2
  340. data/ext/couchbase/core/meta/features.hxx +58 -0
  341. data/ext/couchbase/core/meta/version.cxx +255 -204
  342. data/ext/couchbase/core/meta/version.hxx +31 -20
  343. data/ext/couchbase/core/metrics/logging_meter.cxx +160 -154
  344. data/ext/couchbase/core/metrics/logging_meter.hxx +16 -15
  345. data/ext/couchbase/core/metrics/logging_meter_options.hxx +1 -1
  346. data/ext/couchbase/core/metrics/noop_meter.hxx +14 -13
  347. data/ext/couchbase/core/mozilla_ca_bundle.hxx +2 -2
  348. data/ext/couchbase/core/n1ql_query_options.cxx +31 -31
  349. data/ext/couchbase/core/n1ql_query_options.hxx +22 -21
  350. data/ext/couchbase/core/operation_map.hxx +3 -3
  351. data/ext/couchbase/core/operations/document_analytics.cxx +187 -176
  352. data/ext/couchbase/core/operations/document_analytics.hxx +79 -71
  353. data/ext/couchbase/core/operations/document_append.cxx +18 -15
  354. data/ext/couchbase/core/operations/document_append.hxx +18 -16
  355. data/ext/couchbase/core/operations/document_decrement.cxx +26 -23
  356. data/ext/couchbase/core/operations/document_decrement.hxx +24 -20
  357. data/ext/couchbase/core/operations/document_exists.cxx +23 -21
  358. data/ext/couchbase/core/operations/document_exists.hxx +25 -23
  359. data/ext/couchbase/core/operations/document_get.cxx +17 -15
  360. data/ext/couchbase/core/operations/document_get.hxx +17 -15
  361. data/ext/couchbase/core/operations/document_get_all_replicas.hxx +121 -92
  362. data/ext/couchbase/core/operations/document_get_and_lock.cxx +19 -16
  363. data/ext/couchbase/core/operations/document_get_and_lock.hxx +21 -17
  364. data/ext/couchbase/core/operations/document_get_and_touch.cxx +19 -16
  365. data/ext/couchbase/core/operations/document_get_and_touch.hxx +22 -18
  366. data/ext/couchbase/core/operations/document_get_any_replica.hxx +111 -82
  367. data/ext/couchbase/core/operations/document_get_projected.cxx +193 -184
  368. data/ext/couchbase/core/operations/document_get_projected.hxx +25 -21
  369. data/ext/couchbase/core/operations/document_increment.cxx +26 -23
  370. data/ext/couchbase/core/operations/document_increment.hxx +24 -20
  371. data/ext/couchbase/core/operations/document_insert.cxx +23 -20
  372. data/ext/couchbase/core/operations/document_insert.hxx +20 -18
  373. data/ext/couchbase/core/operations/document_lookup_in.cxx +80 -67
  374. data/ext/couchbase/core/operations/document_lookup_in.hxx +31 -27
  375. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +187 -149
  376. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +190 -145
  377. data/ext/couchbase/core/operations/document_mutate_in.cxx +98 -80
  378. data/ext/couchbase/core/operations/document_mutate_in.hxx +38 -33
  379. data/ext/couchbase/core/operations/document_prepend.cxx +18 -15
  380. data/ext/couchbase/core/operations/document_prepend.hxx +18 -16
  381. data/ext/couchbase/core/operations/document_query.cxx +367 -356
  382. data/ext/couchbase/core/operations/document_query.hxx +83 -79
  383. data/ext/couchbase/core/operations/document_remove.cxx +18 -15
  384. data/ext/couchbase/core/operations/document_remove.hxx +18 -16
  385. data/ext/couchbase/core/operations/document_replace.cxx +27 -24
  386. data/ext/couchbase/core/operations/document_replace.hxx +22 -20
  387. data/ext/couchbase/core/operations/document_search.cxx +322 -308
  388. data/ext/couchbase/core/operations/document_search.hxx +125 -121
  389. data/ext/couchbase/core/operations/document_touch.cxx +16 -14
  390. data/ext/couchbase/core/operations/document_touch.hxx +19 -17
  391. data/ext/couchbase/core/operations/document_unlock.cxx +16 -14
  392. data/ext/couchbase/core/operations/document_unlock.hxx +19 -17
  393. data/ext/couchbase/core/operations/document_upsert.cxx +26 -23
  394. data/ext/couchbase/core/operations/document_upsert.hxx +21 -19
  395. data/ext/couchbase/core/operations/document_view.cxx +169 -159
  396. data/ext/couchbase/core/operations/document_view.hxx +68 -65
  397. data/ext/couchbase/core/operations/http_noop.cxx +38 -35
  398. data/ext/couchbase/core/operations/http_noop.hxx +12 -10
  399. data/ext/couchbase/core/operations/management/analytics_dataset_create.cxx +58 -56
  400. data/ext/couchbase/core/operations/management/analytics_dataset_create.hxx +20 -17
  401. data/ext/couchbase/core/operations/management/analytics_dataset_drop.cxx +49 -44
  402. data/ext/couchbase/core/operations/management/analytics_dataset_drop.hxx +18 -15
  403. data/ext/couchbase/core/operations/management/analytics_dataset_get_all.cxx +46 -43
  404. data/ext/couchbase/core/operations/management/analytics_dataset_get_all.hxx +16 -13
  405. data/ext/couchbase/core/operations/management/analytics_dataverse_create.cxx +48 -43
  406. data/ext/couchbase/core/operations/management/analytics_dataverse_create.hxx +17 -14
  407. data/ext/couchbase/core/operations/management/analytics_dataverse_drop.cxx +48 -43
  408. data/ext/couchbase/core/operations/management/analytics_dataverse_drop.hxx +17 -14
  409. data/ext/couchbase/core/operations/management/analytics_get_pending_mutations.cxx +38 -35
  410. data/ext/couchbase/core/operations/management/analytics_get_pending_mutations.hxx +16 -14
  411. data/ext/couchbase/core/operations/management/analytics_index_create.cxx +68 -66
  412. data/ext/couchbase/core/operations/management/analytics_index_create.hxx +20 -17
  413. data/ext/couchbase/core/operations/management/analytics_index_drop.cxx +56 -51
  414. data/ext/couchbase/core/operations/management/analytics_index_drop.hxx +19 -16
  415. data/ext/couchbase/core/operations/management/analytics_index_get_all.cxx +44 -42
  416. data/ext/couchbase/core/operations/management/analytics_index_get_all.hxx +16 -13
  417. data/ext/couchbase/core/operations/management/analytics_link_connect.cxx +49 -43
  418. data/ext/couchbase/core/operations/management/analytics_link_connect.hxx +23 -20
  419. data/ext/couchbase/core/operations/management/analytics_link_create.cxx +52 -51
  420. data/ext/couchbase/core/operations/management/analytics_link_create.hxx +33 -30
  421. data/ext/couchbase/core/operations/management/analytics_link_disconnect.cxx +46 -42
  422. data/ext/couchbase/core/operations/management/analytics_link_disconnect.hxx +22 -19
  423. data/ext/couchbase/core/operations/management/analytics_link_drop.cxx +70 -67
  424. data/ext/couchbase/core/operations/management/analytics_link_drop.hxx +22 -19
  425. data/ext/couchbase/core/operations/management/analytics_link_get_all.cxx +92 -85
  426. data/ext/couchbase/core/operations/management/analytics_link_get_all.hxx +27 -24
  427. data/ext/couchbase/core/operations/management/analytics_link_replace.cxx +52 -51
  428. data/ext/couchbase/core/operations/management/analytics_link_replace.hxx +33 -30
  429. data/ext/couchbase/core/operations/management/analytics_link_utils.hxx +6 -4
  430. data/ext/couchbase/core/operations/management/analytics_problem.hxx +2 -2
  431. data/ext/couchbase/core/operations/management/bucket_create.cxx +158 -149
  432. data/ext/couchbase/core/operations/management/bucket_create.hxx +14 -12
  433. data/ext/couchbase/core/operations/management/bucket_describe.cxx +118 -42
  434. data/ext/couchbase/core/operations/management/bucket_describe.hxx +47 -22
  435. data/ext/couchbase/core/operations/management/bucket_drop.cxx +19 -18
  436. data/ext/couchbase/core/operations/management/bucket_drop.hxx +13 -11
  437. data/ext/couchbase/core/operations/management/bucket_flush.cxx +25 -24
  438. data/ext/couchbase/core/operations/management/bucket_flush.hxx +13 -11
  439. data/ext/couchbase/core/operations/management/bucket_get.cxx +24 -22
  440. data/ext/couchbase/core/operations/management/bucket_get.hxx +14 -12
  441. data/ext/couchbase/core/operations/management/bucket_get_all.cxx +25 -23
  442. data/ext/couchbase/core/operations/management/bucket_get_all.hxx +13 -11
  443. data/ext/couchbase/core/operations/management/bucket_update.cxx +112 -107
  444. data/ext/couchbase/core/operations/management/bucket_update.hxx +15 -13
  445. data/ext/couchbase/core/operations/management/change_password.cxx +22 -20
  446. data/ext/couchbase/core/operations/management/change_password.hxx +13 -11
  447. data/ext/couchbase/core/operations/management/cluster_describe.cxx +52 -50
  448. data/ext/couchbase/core/operations/management/cluster_describe.hxx +31 -29
  449. data/ext/couchbase/core/operations/management/cluster_developer_preview_enable.cxx +14 -12
  450. data/ext/couchbase/core/operations/management/cluster_developer_preview_enable.hxx +13 -11
  451. data/ext/couchbase/core/operations/management/collection_create.cxx +48 -46
  452. data/ext/couchbase/core/operations/management/collection_create.hxx +19 -16
  453. data/ext/couchbase/core/operations/management/collection_drop.cxx +37 -35
  454. data/ext/couchbase/core/operations/management/collection_drop.hxx +16 -14
  455. data/ext/couchbase/core/operations/management/collection_update.cxx +49 -47
  456. data/ext/couchbase/core/operations/management/collection_update.hxx +19 -16
  457. data/ext/couchbase/core/operations/management/collections_manifest_get.cxx +11 -9
  458. data/ext/couchbase/core/operations/management/collections_manifest_get.hxx +17 -13
  459. data/ext/couchbase/core/operations/management/error_utils.cxx +210 -198
  460. data/ext/couchbase/core/operations/management/error_utils.hxx +3 -1
  461. data/ext/couchbase/core/operations/management/eventing_deploy_function.cxx +30 -28
  462. data/ext/couchbase/core/operations/management/eventing_deploy_function.hxx +17 -14
  463. data/ext/couchbase/core/operations/management/eventing_drop_function.cxx +31 -29
  464. data/ext/couchbase/core/operations/management/eventing_drop_function.hxx +17 -14
  465. data/ext/couchbase/core/operations/management/eventing_get_all_functions.cxx +49 -43
  466. data/ext/couchbase/core/operations/management/eventing_get_all_functions.hxx +17 -14
  467. data/ext/couchbase/core/operations/management/eventing_get_function.cxx +29 -27
  468. data/ext/couchbase/core/operations/management/eventing_get_function.hxx +18 -15
  469. data/ext/couchbase/core/operations/management/eventing_get_status.cxx +45 -39
  470. data/ext/couchbase/core/operations/management/eventing_get_status.hxx +17 -14
  471. data/ext/couchbase/core/operations/management/eventing_pause_function.cxx +30 -28
  472. data/ext/couchbase/core/operations/management/eventing_pause_function.hxx +17 -14
  473. data/ext/couchbase/core/operations/management/eventing_problem.hxx +3 -3
  474. data/ext/couchbase/core/operations/management/eventing_resume_function.cxx +30 -28
  475. data/ext/couchbase/core/operations/management/eventing_resume_function.hxx +17 -14
  476. data/ext/couchbase/core/operations/management/eventing_undeploy_function.cxx +30 -28
  477. data/ext/couchbase/core/operations/management/eventing_undeploy_function.hxx +17 -14
  478. data/ext/couchbase/core/operations/management/eventing_upsert_function.cxx +328 -318
  479. data/ext/couchbase/core/operations/management/eventing_upsert_function.hxx +17 -14
  480. data/ext/couchbase/core/operations/management/freeform.cxx +23 -22
  481. data/ext/couchbase/core/operations/management/freeform.hxx +19 -17
  482. data/ext/couchbase/core/operations/management/group_drop.cxx +18 -17
  483. data/ext/couchbase/core/operations/management/group_drop.hxx +13 -11
  484. data/ext/couchbase/core/operations/management/group_get.cxx +25 -23
  485. data/ext/couchbase/core/operations/management/group_get.hxx +14 -12
  486. data/ext/couchbase/core/operations/management/group_get_all.cxx +23 -22
  487. data/ext/couchbase/core/operations/management/group_get_all.hxx +13 -11
  488. data/ext/couchbase/core/operations/management/group_upsert.cxx +58 -55
  489. data/ext/couchbase/core/operations/management/group_upsert.hxx +14 -12
  490. data/ext/couchbase/core/operations/management/query_index_build.cxx +53 -48
  491. data/ext/couchbase/core/operations/management/query_index_build.hxx +25 -22
  492. data/ext/couchbase/core/operations/management/query_index_build_deferred.hxx +75 -67
  493. data/ext/couchbase/core/operations/management/query_index_create.cxx +128 -122
  494. data/ext/couchbase/core/operations/management/query_index_create.hxx +31 -28
  495. data/ext/couchbase/core/operations/management/query_index_drop.cxx +95 -93
  496. data/ext/couchbase/core/operations/management/query_index_drop.hxx +26 -24
  497. data/ext/couchbase/core/operations/management/query_index_get_all.cxx +97 -93
  498. data/ext/couchbase/core/operations/management/query_index_get_all.hxx +24 -21
  499. data/ext/couchbase/core/operations/management/query_index_get_all_deferred.cxx +66 -62
  500. data/ext/couchbase/core/operations/management/query_index_get_all_deferred.hxx +24 -22
  501. data/ext/couchbase/core/operations/management/role_get_all.cxx +24 -22
  502. data/ext/couchbase/core/operations/management/role_get_all.hxx +13 -11
  503. data/ext/couchbase/core/operations/management/scope_create.cxx +38 -36
  504. data/ext/couchbase/core/operations/management/scope_create.hxx +15 -13
  505. data/ext/couchbase/core/operations/management/scope_drop.cxx +33 -32
  506. data/ext/couchbase/core/operations/management/scope_drop.hxx +15 -13
  507. data/ext/couchbase/core/operations/management/scope_get_all.cxx +27 -25
  508. data/ext/couchbase/core/operations/management/scope_get_all.hxx +14 -12
  509. data/ext/couchbase/core/operations/management/search_get_stats.cxx +12 -10
  510. data/ext/couchbase/core/operations/management/search_get_stats.hxx +13 -11
  511. data/ext/couchbase/core/operations/management/search_index_analyze_document.cxx +72 -67
  512. data/ext/couchbase/core/operations/management/search_index_analyze_document.hxx +20 -18
  513. data/ext/couchbase/core/operations/management/search_index_control_ingest.cxx +62 -59
  514. data/ext/couchbase/core/operations/management/search_index_control_ingest.hxx +19 -16
  515. data/ext/couchbase/core/operations/management/search_index_control_plan_freeze.cxx +62 -59
  516. data/ext/couchbase/core/operations/management/search_index_control_plan_freeze.hxx +19 -17
  517. data/ext/couchbase/core/operations/management/search_index_control_query.cxx +62 -59
  518. data/ext/couchbase/core/operations/management/search_index_control_query.hxx +19 -16
  519. data/ext/couchbase/core/operations/management/search_index_drop.cxx +58 -55
  520. data/ext/couchbase/core/operations/management/search_index_drop.hxx +18 -15
  521. data/ext/couchbase/core/operations/management/search_index_get.cxx +59 -56
  522. data/ext/couchbase/core/operations/management/search_index_get.hxx +18 -16
  523. data/ext/couchbase/core/operations/management/search_index_get_all.cxx +51 -46
  524. data/ext/couchbase/core/operations/management/search_index_get_all.hxx +18 -15
  525. data/ext/couchbase/core/operations/management/search_index_get_documents_count.cxx +66 -61
  526. data/ext/couchbase/core/operations/management/search_index_get_documents_count.hxx +19 -17
  527. data/ext/couchbase/core/operations/management/search_index_get_stats.cxx +38 -36
  528. data/ext/couchbase/core/operations/management/search_index_get_stats.hxx +17 -14
  529. data/ext/couchbase/core/operations/management/search_index_upsert.cxx +98 -95
  530. data/ext/couchbase/core/operations/management/search_index_upsert.hxx +20 -17
  531. data/ext/couchbase/core/operations/management/user_drop.cxx +18 -17
  532. data/ext/couchbase/core/operations/management/user_drop.hxx +16 -12
  533. data/ext/couchbase/core/operations/management/user_get.cxx +25 -23
  534. data/ext/couchbase/core/operations/management/user_get.hxx +17 -13
  535. data/ext/couchbase/core/operations/management/user_get_all.cxx +24 -22
  536. data/ext/couchbase/core/operations/management/user_get_all.hxx +16 -12
  537. data/ext/couchbase/core/operations/management/user_upsert.cxx +63 -60
  538. data/ext/couchbase/core/operations/management/user_upsert.hxx +17 -13
  539. data/ext/couchbase/core/operations/management/view_index_drop.cxx +16 -12
  540. data/ext/couchbase/core/operations/management/view_index_drop.hxx +15 -13
  541. data/ext/couchbase/core/operations/management/view_index_get.cxx +40 -35
  542. data/ext/couchbase/core/operations/management/view_index_get.hxx +16 -14
  543. data/ext/couchbase/core/operations/management/view_index_get_all.cxx +73 -69
  544. data/ext/couchbase/core/operations/management/view_index_get_all.hxx +16 -13
  545. data/ext/couchbase/core/operations/management/view_index_upsert.cxx +39 -35
  546. data/ext/couchbase/core/operations/management/view_index_upsert.hxx +15 -12
  547. data/ext/couchbase/core/origin.cxx +259 -249
  548. data/ext/couchbase/core/origin.hxx +55 -49
  549. data/ext/couchbase/core/pending_operation.hxx +3 -3
  550. data/ext/couchbase/core/ping_collector.hxx +3 -3
  551. data/ext/couchbase/core/ping_options.hxx +30 -30
  552. data/ext/couchbase/core/ping_reporter.hxx +3 -3
  553. data/ext/couchbase/core/platform/backtrace.c +100 -91
  554. data/ext/couchbase/core/platform/base64.cc +135 -134
  555. data/ext/couchbase/core/platform/dirutils.cc +66 -63
  556. data/ext/couchbase/core/platform/random.cc +43 -42
  557. data/ext/couchbase/core/platform/random.h +4 -4
  558. data/ext/couchbase/core/platform/string_hex.cc +42 -40
  559. data/ext/couchbase/core/platform/terminate_handler.cc +54 -52
  560. data/ext/couchbase/core/platform/uuid.cc +47 -47
  561. data/ext/couchbase/core/protocol/client_opcode.hxx +336 -327
  562. data/ext/couchbase/core/protocol/client_opcode_fmt.hxx +291 -291
  563. data/ext/couchbase/core/protocol/client_request.cxx +13 -10
  564. data/ext/couchbase/core/protocol/client_request.hxx +133 -130
  565. data/ext/couchbase/core/protocol/client_response.cxx +40 -40
  566. data/ext/couchbase/core/protocol/client_response.hxx +153 -150
  567. data/ext/couchbase/core/protocol/cmd_append.cxx +24 -23
  568. data/ext/couchbase/core/protocol/cmd_append.hxx +65 -65
  569. data/ext/couchbase/core/protocol/cmd_cluster_map_change_notification.cxx +25 -21
  570. data/ext/couchbase/core/protocol/cmd_cluster_map_change_notification.hxx +33 -25
  571. data/ext/couchbase/core/protocol/cmd_decrement.cxx +38 -38
  572. data/ext/couchbase/core/protocol/cmd_decrement.hxx +87 -87
  573. data/ext/couchbase/core/protocol/cmd_get.cxx +17 -17
  574. data/ext/couchbase/core/protocol/cmd_get.hxx +59 -59
  575. data/ext/couchbase/core/protocol/cmd_get_and_lock.cxx +20 -20
  576. data/ext/couchbase/core/protocol/cmd_get_and_lock.hxx +72 -72
  577. data/ext/couchbase/core/protocol/cmd_get_and_touch.cxx +20 -20
  578. data/ext/couchbase/core/protocol/cmd_get_and_touch.hxx +72 -72
  579. data/ext/couchbase/core/protocol/cmd_get_cluster_config.cxx +46 -39
  580. data/ext/couchbase/core/protocol/cmd_get_cluster_config.hxx +57 -49
  581. data/ext/couchbase/core/protocol/cmd_get_collection_id.cxx +17 -17
  582. data/ext/couchbase/core/protocol/cmd_get_collection_id.hxx +59 -59
  583. data/ext/couchbase/core/protocol/cmd_get_collections_manifest.cxx +16 -14
  584. data/ext/couchbase/core/protocol/cmd_get_collections_manifest.hxx +39 -39
  585. data/ext/couchbase/core/protocol/cmd_get_error_map.cxx +18 -17
  586. data/ext/couchbase/core/protocol/cmd_get_error_map.hxx +62 -62
  587. data/ext/couchbase/core/protocol/cmd_get_meta.cxx +24 -23
  588. data/ext/couchbase/core/protocol/cmd_get_meta.hxx +81 -79
  589. data/ext/couchbase/core/protocol/cmd_get_replica.cxx +23 -23
  590. data/ext/couchbase/core/protocol/cmd_get_replica.hxx +44 -44
  591. data/ext/couchbase/core/protocol/cmd_hello.cxx +28 -27
  592. data/ext/couchbase/core/protocol/cmd_hello.hxx +106 -105
  593. data/ext/couchbase/core/protocol/cmd_increment.cxx +38 -38
  594. data/ext/couchbase/core/protocol/cmd_increment.hxx +87 -87
  595. data/ext/couchbase/core/protocol/cmd_info.hxx +3 -3
  596. data/ext/couchbase/core/protocol/cmd_insert.cxx +27 -27
  597. data/ext/couchbase/core/protocol/cmd_insert.hxx +81 -81
  598. data/ext/couchbase/core/protocol/cmd_lookup_in.cxx +54 -51
  599. data/ext/couchbase/core/protocol/cmd_lookup_in.hxx +90 -90
  600. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +54 -51
  601. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +88 -88
  602. data/ext/couchbase/core/protocol/cmd_mutate_in.cxx +105 -97
  603. data/ext/couchbase/core/protocol/cmd_mutate_in.hxx +161 -153
  604. data/ext/couchbase/core/protocol/cmd_noop.cxx +4 -4
  605. data/ext/couchbase/core/protocol/cmd_noop.hxx +32 -32
  606. data/ext/couchbase/core/protocol/cmd_observe_seqno.cxx +36 -34
  607. data/ext/couchbase/core/protocol/cmd_observe_seqno.hxx +89 -89
  608. data/ext/couchbase/core/protocol/cmd_prepend.cxx +22 -22
  609. data/ext/couchbase/core/protocol/cmd_prepend.hxx +63 -63
  610. data/ext/couchbase/core/protocol/cmd_remove.cxx +23 -23
  611. data/ext/couchbase/core/protocol/cmd_remove.hxx +54 -54
  612. data/ext/couchbase/core/protocol/cmd_replace.cxx +28 -28
  613. data/ext/couchbase/core/protocol/cmd_replace.hxx +88 -88
  614. data/ext/couchbase/core/protocol/cmd_sasl_auth.cxx +17 -15
  615. data/ext/couchbase/core/protocol/cmd_sasl_auth.hxx +56 -56
  616. data/ext/couchbase/core/protocol/cmd_sasl_list_mechs.cxx +24 -19
  617. data/ext/couchbase/core/protocol/cmd_sasl_list_mechs.hxx +39 -39
  618. data/ext/couchbase/core/protocol/cmd_sasl_step.cxx +17 -15
  619. data/ext/couchbase/core/protocol/cmd_sasl_step.hxx +56 -56
  620. data/ext/couchbase/core/protocol/cmd_select_bucket.cxx +6 -6
  621. data/ext/couchbase/core/protocol/cmd_select_bucket.hxx +36 -36
  622. data/ext/couchbase/core/protocol/cmd_touch.cxx +8 -8
  623. data/ext/couchbase/core/protocol/cmd_touch.hxx +38 -38
  624. data/ext/couchbase/core/protocol/cmd_unlock.cxx +5 -5
  625. data/ext/couchbase/core/protocol/cmd_unlock.hxx +36 -36
  626. data/ext/couchbase/core/protocol/cmd_upsert.cxx +28 -28
  627. data/ext/couchbase/core/protocol/cmd_upsert.hxx +83 -83
  628. data/ext/couchbase/core/protocol/datatype.hxx +19 -18
  629. data/ext/couchbase/core/protocol/frame_info_id.hxx +108 -103
  630. data/ext/couchbase/core/protocol/frame_info_id_fmt.hxx +45 -45
  631. data/ext/couchbase/core/protocol/frame_info_utils.cxx +24 -21
  632. data/ext/couchbase/core/protocol/frame_info_utils.hxx +3 -1
  633. data/ext/couchbase/core/protocol/hello_feature.hxx +211 -175
  634. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +93 -90
  635. data/ext/couchbase/core/protocol/magic.hxx +24 -24
  636. data/ext/couchbase/core/protocol/magic_fmt.hxx +30 -30
  637. data/ext/couchbase/core/protocol/server_opcode.hxx +11 -11
  638. data/ext/couchbase/core/protocol/server_opcode_fmt.hxx +18 -18
  639. data/ext/couchbase/core/protocol/server_request.hxx +90 -86
  640. data/ext/couchbase/core/protocol/status.cxx +138 -138
  641. data/ext/couchbase/core/protocol/status.hxx +86 -86
  642. data/ext/couchbase/core/query_context.hxx +44 -43
  643. data/ext/couchbase/core/range_scan_load_balancer.cxx +51 -50
  644. data/ext/couchbase/core/range_scan_load_balancer.hxx +26 -25
  645. data/ext/couchbase/core/range_scan_options.cxx +2 -2
  646. data/ext/couchbase/core/range_scan_options.hxx +62 -59
  647. data/ext/couchbase/core/range_scan_orchestrator.cxx +515 -470
  648. data/ext/couchbase/core/range_scan_orchestrator.hxx +23 -18
  649. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +10 -10
  650. data/ext/couchbase/core/resource_units.hxx +2 -2
  651. data/ext/couchbase/core/response_handler.hxx +8 -8
  652. data/ext/couchbase/core/retry_orchestrator.cxx +27 -19
  653. data/ext/couchbase/core/retry_orchestrator.hxx +3 -2
  654. data/ext/couchbase/core/sasl/client.cc +22 -18
  655. data/ext/couchbase/core/sasl/client.h +66 -62
  656. data/ext/couchbase/core/sasl/context.cc +4 -4
  657. data/ext/couchbase/core/sasl/context.h +19 -19
  658. data/ext/couchbase/core/sasl/error.h +12 -1
  659. data/ext/couchbase/core/sasl/error_fmt.h +42 -42
  660. data/ext/couchbase/core/sasl/mechanism.cc +13 -10
  661. data/ext/couchbase/core/sasl/mechanism.h +8 -3
  662. data/ext/couchbase/core/sasl/plain/plain.cc +8 -8
  663. data/ext/couchbase/core/sasl/plain/plain.h +25 -24
  664. data/ext/couchbase/core/sasl/scram-sha/scram-sha.cc +225 -218
  665. data/ext/couchbase/core/sasl/scram-sha/scram-sha.h +133 -115
  666. data/ext/couchbase/core/sasl/scram-sha/stringutils.cc +20 -20
  667. data/ext/couchbase/core/scan_result.cxx +38 -38
  668. data/ext/couchbase/core/scan_result.hxx +16 -16
  669. data/ext/couchbase/core/search_highlight_style.hxx +4 -1
  670. data/ext/couchbase/core/search_query_options.cxx +21 -21
  671. data/ext/couchbase/core/search_query_options.hxx +19 -18
  672. data/ext/couchbase/core/search_scan_consistency.hxx +3 -1
  673. data/ext/couchbase/core/seed_config.cxx +10 -7
  674. data/ext/couchbase/core/seed_config.hxx +8 -8
  675. data/ext/couchbase/core/service_type.hxx +7 -7
  676. data/ext/couchbase/core/service_type_fmt.hxx +33 -33
  677. data/ext/couchbase/core/stats_options.hxx +13 -13
  678. data/ext/couchbase/core/subdoc_options.hxx +60 -58
  679. data/ext/couchbase/core/tls_verify_mode.hxx +2 -2
  680. data/ext/couchbase/core/topology/capabilities.hxx +83 -83
  681. data/ext/couchbase/core/topology/capabilities_fmt.hxx +111 -111
  682. data/ext/couchbase/core/topology/collections_manifest.hxx +14 -14
  683. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +23 -21
  684. data/ext/couchbase/core/topology/collections_manifest_json.hxx +26 -25
  685. data/ext/couchbase/core/topology/configuration.cxx +213 -192
  686. data/ext/couchbase/core/topology/configuration.hxx +104 -91
  687. data/ext/couchbase/core/topology/configuration_fmt.hxx +131 -128
  688. data/ext/couchbase/core/topology/configuration_json.hxx +276 -242
  689. data/ext/couchbase/core/topology/error_map.hxx +5 -5
  690. data/ext/couchbase/core/topology/error_map_json.hxx +65 -60
  691. data/ext/couchbase/core/tracing/constants.hxx +153 -153
  692. data/ext/couchbase/core/tracing/noop_tracer.hxx +29 -28
  693. data/ext/couchbase/core/tracing/threshold_logging_options.hxx +30 -30
  694. data/ext/couchbase/core/tracing/threshold_logging_tracer.cxx +354 -344
  695. data/ext/couchbase/core/tracing/threshold_logging_tracer.hxx +12 -12
  696. data/ext/couchbase/core/transactions/active_transaction_record.cxx +153 -33
  697. data/ext/couchbase/core/transactions/active_transaction_record.hxx +30 -118
  698. data/ext/couchbase/core/transactions/async_attempt_context.cxx +8 -2
  699. data/ext/couchbase/core/transactions/async_attempt_context.hxx +163 -127
  700. data/ext/couchbase/core/transactions/atr_cleanup_entry.cxx +358 -334
  701. data/ext/couchbase/core/transactions/atr_ids.cxx +270 -185
  702. data/ext/couchbase/core/transactions/atr_ids.hxx +4 -4
  703. data/ext/couchbase/core/transactions/attempt_context.cxx +9 -5
  704. data/ext/couchbase/core/transactions/attempt_context.hxx +194 -154
  705. data/ext/couchbase/core/transactions/attempt_context_impl.cxx +3278 -2159
  706. data/ext/couchbase/core/transactions/attempt_context_impl.hxx +446 -573
  707. data/ext/couchbase/core/transactions/attempt_context_testing_hooks.cxx +15 -10
  708. data/ext/couchbase/core/transactions/attempt_context_testing_hooks.hxx +58 -49
  709. data/ext/couchbase/core/transactions/attempt_state.hxx +72 -72
  710. data/ext/couchbase/core/transactions/binary.cxx +3 -3
  711. data/ext/couchbase/core/transactions/cleanup_testing_hooks.cxx +2 -2
  712. data/ext/couchbase/core/transactions/cleanup_testing_hooks.hxx +28 -24
  713. data/ext/couchbase/core/transactions/document_metadata.hxx +68 -68
  714. data/ext/couchbase/core/transactions/durability_level.hxx +53 -53
  715. data/ext/couchbase/core/transactions/error_class.hxx +12 -12
  716. data/ext/couchbase/core/transactions/error_list.hxx +22 -22
  717. data/ext/couchbase/core/transactions/exceptions.cxx +167 -114
  718. data/ext/couchbase/core/transactions/exceptions.hxx +170 -139
  719. data/ext/couchbase/core/transactions/exceptions_fmt.hxx +105 -0
  720. data/ext/couchbase/core/transactions/forward_compat.cxx +220 -0
  721. data/ext/couchbase/core/transactions/forward_compat.hxx +63 -207
  722. data/ext/couchbase/core/transactions/internal/atr_cleanup_entry.hxx +110 -102
  723. data/ext/couchbase/core/transactions/internal/atr_entry.hxx +144 -144
  724. data/ext/couchbase/core/transactions/internal/client_record.hxx +53 -50
  725. data/ext/couchbase/core/transactions/internal/doc_record.cxx +5 -5
  726. data/ext/couchbase/core/transactions/internal/doc_record.hxx +38 -35
  727. data/ext/couchbase/core/transactions/internal/doc_record_fmt.hxx +17 -16
  728. data/ext/couchbase/core/transactions/internal/exceptions_internal.hxx +238 -281
  729. data/ext/couchbase/core/transactions/internal/exceptions_internal_fmt.hxx +103 -0
  730. data/ext/couchbase/core/transactions/internal/logging.hxx +52 -29
  731. data/ext/couchbase/core/transactions/internal/transaction_attempt.hxx +3 -3
  732. data/ext/couchbase/core/transactions/internal/transaction_context.hxx +136 -120
  733. data/ext/couchbase/core/transactions/internal/transaction_fields.hxx +2 -1
  734. data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +127 -122
  735. data/ext/couchbase/core/transactions/internal/utils.hxx +244 -219
  736. data/ext/couchbase/core/transactions/result.cxx +41 -40
  737. data/ext/couchbase/core/transactions/result.hxx +143 -141
  738. data/ext/couchbase/core/transactions/result_fmt.hxx +21 -20
  739. data/ext/couchbase/core/transactions/staged_mutation.cxx +759 -627
  740. data/ext/couchbase/core/transactions/staged_mutation.hxx +175 -156
  741. data/ext/couchbase/core/transactions/transaction_context.cxx +231 -179
  742. data/ext/couchbase/core/transactions/transaction_get_result.cxx +185 -198
  743. data/ext/couchbase/core/transactions/transaction_get_result.hxx +207 -222
  744. data/ext/couchbase/core/transactions/transaction_keyspace.cxx +15 -11
  745. data/ext/couchbase/core/transactions/transaction_links.cxx +11 -7
  746. data/ext/couchbase/core/transactions/transaction_links.hxx +222 -201
  747. data/ext/couchbase/core/transactions/transaction_options.cxx +44 -41
  748. data/ext/couchbase/core/transactions/transactions.cxx +167 -125
  749. data/ext/couchbase/core/transactions/transactions_cleanup.cxx +491 -424
  750. data/ext/couchbase/core/transactions/transactions_config.cxx +25 -19
  751. data/ext/couchbase/core/transactions/uid_generator.cxx +3 -3
  752. data/ext/couchbase/core/transactions/uid_generator.hxx +2 -2
  753. data/ext/couchbase/core/transactions/utils.cxx +82 -69
  754. data/ext/couchbase/core/transactions/waitable_op_list.hxx +154 -140
  755. data/ext/couchbase/core/transactions.hxx +184 -180
  756. data/ext/couchbase/core/utils/binary.cxx +3 -3
  757. data/ext/couchbase/core/utils/binary.hxx +19 -15
  758. data/ext/couchbase/core/utils/byteswap.hxx +17 -17
  759. data/ext/couchbase/core/utils/connection_string.cxx +395 -328
  760. data/ext/couchbase/core/utils/connection_string.hxx +37 -36
  761. data/ext/couchbase/core/utils/crc32.hxx +42 -34
  762. data/ext/couchbase/core/utils/duration_parser.cxx +142 -133
  763. data/ext/couchbase/core/utils/duration_parser.hxx +9 -9
  764. data/ext/couchbase/core/utils/join_strings.hxx +24 -24
  765. data/ext/couchbase/core/utils/json.cxx +234 -228
  766. data/ext/couchbase/core/utils/json.hxx +12 -12
  767. data/ext/couchbase/core/utils/json_stream_control.hxx +8 -8
  768. data/ext/couchbase/core/utils/json_streaming_lexer.cxx +288 -263
  769. data/ext/couchbase/core/utils/json_streaming_lexer.hxx +20 -17
  770. data/ext/couchbase/core/utils/keyspace.hxx +22 -21
  771. data/ext/couchbase/core/utils/movable_function.hxx +78 -76
  772. data/ext/couchbase/core/utils/mutation_token.cxx +7 -3
  773. data/ext/couchbase/core/utils/mutation_token.hxx +3 -1
  774. data/ext/couchbase/core/utils/name_codec.hxx +13 -13
  775. data/ext/couchbase/core/utils/split_string.cxx +9 -9
  776. data/ext/couchbase/core/utils/split_string.hxx +2 -2
  777. data/ext/couchbase/core/utils/unsigned_leb128.hxx +92 -88
  778. data/ext/couchbase/core/utils/url_codec.cxx +301 -297
  779. data/ext/couchbase/core/utils/url_codec.hxx +35 -35
  780. data/ext/couchbase/core/vector_query_combination.hxx +4 -1
  781. data/ext/couchbase/core/view_on_error.hxx +4 -3
  782. data/ext/couchbase/core/view_query_options.cxx +21 -21
  783. data/ext/couchbase/core/view_query_options.hxx +23 -22
  784. data/ext/couchbase/core/view_scan_consistency.hxx +3 -3
  785. data/ext/couchbase/core/view_sort_order.hxx +4 -1
  786. data/ext/couchbase/core/wait_until_ready_options.hxx +11 -10
  787. data/ext/couchbase/couchbase/allow_querying_search_index_options.hxx +11 -11
  788. data/ext/couchbase/couchbase/analytics_index_manager.hxx +423 -405
  789. data/ext/couchbase/couchbase/analytics_meta_data.hxx +105 -105
  790. data/ext/couchbase/couchbase/analytics_metrics.hxx +120 -118
  791. data/ext/couchbase/couchbase/analytics_options.hxx +318 -292
  792. data/ext/couchbase/couchbase/analytics_result.hxx +56 -55
  793. data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +24 -21
  794. data/ext/couchbase/couchbase/analytics_status.hxx +10 -10
  795. data/ext/couchbase/couchbase/analytics_warning.hxx +44 -43
  796. data/ext/couchbase/couchbase/analyze_document_options.hxx +9 -9
  797. data/ext/couchbase/couchbase/append_options.hxx +51 -47
  798. data/ext/couchbase/couchbase/behavior_options.hxx +75 -69
  799. data/ext/couchbase/couchbase/best_effort_retry_strategy.hxx +12 -10
  800. data/ext/couchbase/couchbase/binary_collection.hxx +213 -183
  801. data/ext/couchbase/couchbase/boolean_field_query.hxx +38 -38
  802. data/ext/couchbase/couchbase/boolean_query.hxx +166 -157
  803. data/ext/couchbase/couchbase/bucket.hxx +69 -68
  804. data/ext/couchbase/couchbase/bucket_manager.hxx +97 -88
  805. data/ext/couchbase/couchbase/build_query_index_options.hxx +22 -21
  806. data/ext/couchbase/couchbase/cas.hxx +74 -73
  807. data/ext/couchbase/couchbase/certificate_authenticator.hxx +10 -10
  808. data/ext/couchbase/couchbase/cluster.hxx +266 -310
  809. data/ext/couchbase/couchbase/cluster_options.hxx +235 -241
  810. data/ext/couchbase/couchbase/codec/binary_noop_serializer.hxx +11 -11
  811. data/ext/couchbase/couchbase/codec/codec_flags.hxx +39 -35
  812. data/ext/couchbase/couchbase/codec/encoded_value.hxx +15 -2
  813. data/ext/couchbase/couchbase/codec/json_transcoder.hxx +17 -15
  814. data/ext/couchbase/couchbase/codec/raw_binary_transcoder.hxx +19 -17
  815. data/ext/couchbase/couchbase/codec/raw_json_transcoder.hxx +31 -24
  816. data/ext/couchbase/couchbase/codec/raw_string_transcoder.hxx +20 -18
  817. data/ext/couchbase/couchbase/codec/tao_json_serializer.hxx +38 -30
  818. data/ext/couchbase/couchbase/collection.hxx +1007 -902
  819. data/ext/couchbase/couchbase/collection_manager.hxx +115 -107
  820. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +200 -188
  821. data/ext/couchbase/couchbase/common_durability_options.hxx +68 -62
  822. data/ext/couchbase/couchbase/common_options.hxx +67 -67
  823. data/ext/couchbase/couchbase/compression_options.hxx +33 -33
  824. data/ext/couchbase/couchbase/configuration_profile.hxx +12 -11
  825. data/ext/couchbase/couchbase/configuration_profiles_registry.hxx +24 -22
  826. data/ext/couchbase/couchbase/conjunction_query.hxx +47 -45
  827. data/ext/couchbase/couchbase/connect_link_analytics_options.hxx +74 -72
  828. data/ext/couchbase/couchbase/counter_result.hxx +32 -32
  829. data/ext/couchbase/couchbase/create_bucket_options.hxx +9 -10
  830. data/ext/couchbase/couchbase/create_collection_options.hxx +35 -34
  831. data/ext/couchbase/couchbase/create_dataset_analytics_options.hxx +76 -76
  832. data/ext/couchbase/couchbase/create_dataverse_analytics_options.hxx +44 -44
  833. data/ext/couchbase/couchbase/create_index_analytics_options.hxx +60 -60
  834. data/ext/couchbase/couchbase/create_link_analytics_options.hxx +25 -25
  835. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +95 -94
  836. data/ext/couchbase/couchbase/create_query_index_options.hxx +97 -96
  837. data/ext/couchbase/couchbase/create_scope_options.hxx +9 -9
  838. data/ext/couchbase/couchbase/date_range.hxx +29 -27
  839. data/ext/couchbase/couchbase/date_range_facet.hxx +20 -20
  840. data/ext/couchbase/couchbase/date_range_facet_result.hxx +14 -14
  841. data/ext/couchbase/couchbase/date_range_query.hxx +219 -205
  842. data/ext/couchbase/couchbase/decrement_options.hxx +93 -91
  843. data/ext/couchbase/couchbase/diagnostics_options.hxx +42 -41
  844. data/ext/couchbase/couchbase/diagnostics_result.hxx +82 -83
  845. data/ext/couchbase/couchbase/disallow_querying_search_index_options.hxx +11 -10
  846. data/ext/couchbase/couchbase/disconnect_link_analytics_options.hxx +62 -62
  847. data/ext/couchbase/couchbase/disjunction_query.hxx +61 -60
  848. data/ext/couchbase/couchbase/dns_options.hxx +30 -30
  849. data/ext/couchbase/couchbase/doc_id_query.hxx +69 -69
  850. data/ext/couchbase/couchbase/drop_bucket_options.hxx +9 -9
  851. data/ext/couchbase/couchbase/drop_collection_options.hxx +9 -9
  852. data/ext/couchbase/couchbase/drop_dataset_analytics_options.hxx +60 -60
  853. data/ext/couchbase/couchbase/drop_dataverse_analytics_options.hxx +44 -44
  854. data/ext/couchbase/couchbase/drop_index_analytics_options.hxx +60 -60
  855. data/ext/couchbase/couchbase/drop_link_analytics_options.hxx +25 -25
  856. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +58 -58
  857. data/ext/couchbase/couchbase/drop_query_index_options.hxx +44 -44
  858. data/ext/couchbase/couchbase/drop_scope_options.hxx +9 -9
  859. data/ext/couchbase/couchbase/drop_search_index_options.hxx +9 -9
  860. data/ext/couchbase/couchbase/durability_level.hxx +32 -29
  861. data/ext/couchbase/couchbase/endpoint_diagnostics.hxx +171 -171
  862. data/ext/couchbase/couchbase/endpoint_ping_report.hxx +166 -169
  863. data/ext/couchbase/couchbase/error.hxx +51 -0
  864. data/ext/couchbase/couchbase/error_codes.hxx +975 -940
  865. data/ext/couchbase/couchbase/error_context.hxx +19 -152
  866. data/ext/couchbase/couchbase/exists_options.hxx +25 -24
  867. data/ext/couchbase/couchbase/exists_result.hxx +32 -32
  868. data/ext/couchbase/couchbase/fail_fast_retry_strategy.hxx +4 -4
  869. data/ext/couchbase/couchbase/flush_bucket_options.hxx +9 -9
  870. data/ext/couchbase/couchbase/fmt/analytics_scan_consistency.hxx +18 -18
  871. data/ext/couchbase/couchbase/fmt/analytics_status.hxx +42 -42
  872. data/ext/couchbase/couchbase/fmt/cas.hxx +10 -10
  873. data/ext/couchbase/couchbase/fmt/durability_level.hxx +24 -24
  874. data/ext/couchbase/couchbase/fmt/error.hxx +53 -0
  875. data/ext/couchbase/couchbase/fmt/error_context.hxx +43 -0
  876. data/ext/couchbase/couchbase/fmt/mutation_token.hxx +15 -11
  877. data/ext/couchbase/couchbase/fmt/query_profile.hxx +21 -21
  878. data/ext/couchbase/couchbase/fmt/query_scan_consistency.hxx +18 -18
  879. data/ext/couchbase/couchbase/fmt/query_status.hxx +42 -42
  880. data/ext/couchbase/couchbase/fmt/retry_reason.hxx +75 -75
  881. data/ext/couchbase/couchbase/fmt/search_scan_consistency.hxx +15 -15
  882. data/ext/couchbase/couchbase/fmt/tls_verify_mode.hxx +18 -18
  883. data/ext/couchbase/couchbase/fmt/transaction_keyspace.hxx +15 -11
  884. data/ext/couchbase/couchbase/fork_event.hxx +12 -12
  885. data/ext/couchbase/couchbase/freeze_plan_search_index_options.hxx +9 -9
  886. data/ext/couchbase/couchbase/geo_bounding_box_query.hxx +71 -64
  887. data/ext/couchbase/couchbase/geo_distance_query.hxx +73 -66
  888. data/ext/couchbase/couchbase/geo_point.hxx +2 -2
  889. data/ext/couchbase/couchbase/geo_polygon_query.hxx +40 -39
  890. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +9 -9
  891. data/ext/couchbase/couchbase/get_all_datasets_analytics_options.hxx +25 -25
  892. data/ext/couchbase/couchbase/get_all_indexes_analytics_options.hxx +26 -25
  893. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +27 -25
  894. data/ext/couchbase/couchbase/get_all_replicas_options.hxx +49 -26
  895. data/ext/couchbase/couchbase/get_all_scopes_options.hxx +9 -9
  896. data/ext/couchbase/couchbase/get_all_search_indexes_options.hxx +9 -9
  897. data/ext/couchbase/couchbase/get_and_lock_options.hxx +25 -24
  898. data/ext/couchbase/couchbase/get_and_touch_options.hxx +25 -24
  899. data/ext/couchbase/couchbase/get_any_replica_options.hxx +49 -26
  900. data/ext/couchbase/couchbase/get_bucket_options.hxx +9 -9
  901. data/ext/couchbase/couchbase/get_indexed_search_index_options.hxx +9 -9
  902. data/ext/couchbase/couchbase/get_links_analytics_options.hxx +74 -74
  903. data/ext/couchbase/couchbase/get_options.hxx +63 -60
  904. data/ext/couchbase/couchbase/get_pending_mutations_analytics_options.hxx +30 -28
  905. data/ext/couchbase/couchbase/get_replica_result.hxx +79 -75
  906. data/ext/couchbase/couchbase/get_result.hxx +86 -80
  907. data/ext/couchbase/couchbase/get_search_index_options.hxx +9 -9
  908. data/ext/couchbase/couchbase/highlight_style.hxx +14 -14
  909. data/ext/couchbase/couchbase/increment_options.hxx +94 -91
  910. data/ext/couchbase/couchbase/insert_options.hxx +62 -59
  911. data/ext/couchbase/couchbase/ip_protocol.hxx +3 -3
  912. data/ext/couchbase/couchbase/logger.hxx +51 -0
  913. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +54 -43
  914. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +54 -44
  915. data/ext/couchbase/couchbase/lookup_in_options.hxx +40 -40
  916. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +38 -35
  917. data/ext/couchbase/couchbase/lookup_in_result.hxx +222 -216
  918. data/ext/couchbase/couchbase/lookup_in_specs.hxx +101 -101
  919. data/ext/couchbase/couchbase/management/analytics_dataset.hxx +16 -16
  920. data/ext/couchbase/couchbase/management/analytics_index.hxx +16 -16
  921. data/ext/couchbase/couchbase/management/analytics_link.hxx +193 -189
  922. data/ext/couchbase/couchbase/management/bucket_settings.hxx +91 -75
  923. data/ext/couchbase/couchbase/management/collection_spec.hxx +4 -4
  924. data/ext/couchbase/couchbase/management/query_index.hxx +10 -10
  925. data/ext/couchbase/couchbase/management/scope_spec.hxx +2 -2
  926. data/ext/couchbase/couchbase/management/search_index.hxx +9 -9
  927. data/ext/couchbase/couchbase/match_all_query.hxx +10 -9
  928. data/ext/couchbase/couchbase/match_none_query.hxx +10 -9
  929. data/ext/couchbase/couchbase/match_operator.hxx +15 -14
  930. data/ext/couchbase/couchbase/match_phrase_query.hxx +70 -65
  931. data/ext/couchbase/couchbase/match_query.hxx +115 -114
  932. data/ext/couchbase/couchbase/metrics/meter.hxx +33 -30
  933. data/ext/couchbase/couchbase/metrics/otel_meter.hxx +86 -74
  934. data/ext/couchbase/couchbase/metrics_options.hxx +34 -34
  935. data/ext/couchbase/couchbase/mutate_in_options.hxx +160 -149
  936. data/ext/couchbase/couchbase/mutate_in_result.hxx +130 -123
  937. data/ext/couchbase/couchbase/mutate_in_specs.hxx +473 -454
  938. data/ext/couchbase/couchbase/mutation_result.hxx +32 -32
  939. data/ext/couchbase/couchbase/mutation_state.hxx +35 -34
  940. data/ext/couchbase/couchbase/mutation_token.hxx +78 -78
  941. data/ext/couchbase/couchbase/network_options.hxx +101 -72
  942. data/ext/couchbase/couchbase/numeric_range.hxx +26 -26
  943. data/ext/couchbase/couchbase/numeric_range_facet.hxx +20 -20
  944. data/ext/couchbase/couchbase/numeric_range_facet_result.hxx +14 -14
  945. data/ext/couchbase/couchbase/numeric_range_query.hxx +97 -95
  946. data/ext/couchbase/couchbase/password_authenticator.hxx +17 -17
  947. data/ext/couchbase/couchbase/pause_ingest_search_index_options.hxx +11 -10
  948. data/ext/couchbase/couchbase/persist_to.hxx +45 -44
  949. data/ext/couchbase/couchbase/phrase_query.hxx +69 -65
  950. data/ext/couchbase/couchbase/ping_options.hxx +55 -54
  951. data/ext/couchbase/couchbase/ping_result.hxx +79 -77
  952. data/ext/couchbase/couchbase/prefix_query.hxx +43 -40
  953. data/ext/couchbase/couchbase/prepend_options.hxx +51 -47
  954. data/ext/couchbase/couchbase/query_index_manager.hxx +207 -199
  955. data/ext/couchbase/couchbase/query_meta_data.hxx +120 -120
  956. data/ext/couchbase/couchbase/query_metrics.hxx +135 -133
  957. data/ext/couchbase/couchbase/query_options.hxx +518 -493
  958. data/ext/couchbase/couchbase/query_profile.hxx +29 -26
  959. data/ext/couchbase/couchbase/query_result.hxx +56 -55
  960. data/ext/couchbase/couchbase/query_scan_consistency.hxx +24 -21
  961. data/ext/couchbase/couchbase/query_status.hxx +10 -10
  962. data/ext/couchbase/couchbase/query_string_query.hxx +34 -29
  963. data/ext/couchbase/couchbase/query_warning.hxx +75 -71
  964. data/ext/couchbase/couchbase/read_preference.hxx +58 -0
  965. data/ext/couchbase/couchbase/regexp_query.hxx +40 -39
  966. data/ext/couchbase/couchbase/remove_options.hxx +51 -47
  967. data/ext/couchbase/couchbase/replace_link_analytics_options.hxx +25 -25
  968. data/ext/couchbase/couchbase/replace_options.hxx +112 -104
  969. data/ext/couchbase/couchbase/replicate_to.hxx +28 -28
  970. data/ext/couchbase/couchbase/result.hxx +28 -28
  971. data/ext/couchbase/couchbase/resume_ingest_search_index_options.hxx +11 -10
  972. data/ext/couchbase/couchbase/retry_action.hxx +10 -10
  973. data/ext/couchbase/couchbase/retry_reason.hxx +53 -51
  974. data/ext/couchbase/couchbase/retry_request.hxx +7 -7
  975. data/ext/couchbase/couchbase/retry_strategy.hxx +4 -4
  976. data/ext/couchbase/couchbase/scan_options.hxx +114 -108
  977. data/ext/couchbase/couchbase/scan_result.hxx +97 -96
  978. data/ext/couchbase/couchbase/scan_result_item.hxx +120 -118
  979. data/ext/couchbase/couchbase/scan_type.hxx +237 -232
  980. data/ext/couchbase/couchbase/scope.hxx +164 -157
  981. data/ext/couchbase/couchbase/scope_search_index_manager.hxx +263 -238
  982. data/ext/couchbase/couchbase/search_date_range.hxx +32 -29
  983. data/ext/couchbase/couchbase/search_facet.hxx +25 -25
  984. data/ext/couchbase/couchbase/search_facet_result.hxx +11 -11
  985. data/ext/couchbase/couchbase/search_geo_distance_units.hxx +11 -1
  986. data/ext/couchbase/couchbase/search_index_manager.hxx +261 -238
  987. data/ext/couchbase/couchbase/search_meta_data.hxx +37 -37
  988. data/ext/couchbase/couchbase/search_metrics.hxx +84 -83
  989. data/ext/couchbase/couchbase/search_numeric_range.hxx +32 -32
  990. data/ext/couchbase/couchbase/search_options.hxx +449 -435
  991. data/ext/couchbase/couchbase/search_query.hxx +32 -30
  992. data/ext/couchbase/couchbase/search_request.hxx +69 -68
  993. data/ext/couchbase/couchbase/search_result.hxx +29 -26
  994. data/ext/couchbase/couchbase/search_row.hxx +52 -52
  995. data/ext/couchbase/couchbase/search_row_location.hxx +20 -20
  996. data/ext/couchbase/couchbase/search_row_locations.hxx +39 -38
  997. data/ext/couchbase/couchbase/search_scan_consistency.hxx +11 -10
  998. data/ext/couchbase/couchbase/search_sort.hxx +20 -20
  999. data/ext/couchbase/couchbase/search_sort_field.hxx +77 -71
  1000. data/ext/couchbase/couchbase/search_sort_field_missing.hxx +2 -2
  1001. data/ext/couchbase/couchbase/search_sort_field_mode.hxx +3 -3
  1002. data/ext/couchbase/couchbase/search_sort_field_type.hxx +4 -4
  1003. data/ext/couchbase/couchbase/search_sort_geo_distance.hxx +41 -41
  1004. data/ext/couchbase/couchbase/search_sort_id.hxx +23 -23
  1005. data/ext/couchbase/couchbase/search_sort_score.hxx +23 -23
  1006. data/ext/couchbase/couchbase/search_term_range.hxx +17 -17
  1007. data/ext/couchbase/couchbase/security_options.hxx +50 -50
  1008. data/ext/couchbase/couchbase/service_type.hxx +34 -34
  1009. data/ext/couchbase/couchbase/store_semantics.hxx +28 -28
  1010. data/ext/couchbase/couchbase/subdoc/array_add_unique.hxx +54 -54
  1011. data/ext/couchbase/couchbase/subdoc/array_append.hxx +40 -40
  1012. data/ext/couchbase/couchbase/subdoc/array_insert.hxx +41 -41
  1013. data/ext/couchbase/couchbase/subdoc/array_prepend.hxx +41 -41
  1014. data/ext/couchbase/couchbase/subdoc/count.hxx +24 -24
  1015. data/ext/couchbase/couchbase/subdoc/counter.hxx +41 -41
  1016. data/ext/couchbase/couchbase/subdoc/exists.hxx +24 -24
  1017. data/ext/couchbase/couchbase/subdoc/get.hxx +45 -29
  1018. data/ext/couchbase/couchbase/subdoc/insert.hxx +70 -54
  1019. data/ext/couchbase/couchbase/subdoc/lookup_in_macro.hxx +13 -12
  1020. data/ext/couchbase/couchbase/subdoc/mutate_in_macro.hxx +7 -2
  1021. data/ext/couchbase/couchbase/subdoc/remove.hxx +24 -24
  1022. data/ext/couchbase/couchbase/subdoc/replace.hxx +55 -39
  1023. data/ext/couchbase/couchbase/subdoc/upsert.hxx +70 -54
  1024. data/ext/couchbase/couchbase/term_facet.hxx +16 -16
  1025. data/ext/couchbase/couchbase/term_facet_result.hxx +14 -14
  1026. data/ext/couchbase/couchbase/term_query.hxx +107 -104
  1027. data/ext/couchbase/couchbase/term_range_query.hxx +99 -96
  1028. data/ext/couchbase/couchbase/timeout_options.hxx +118 -112
  1029. data/ext/couchbase/couchbase/tls_verify_mode.hxx +2 -2
  1030. data/ext/couchbase/couchbase/touch_options.hxx +25 -24
  1031. data/ext/couchbase/couchbase/tracing/otel_tracer.hxx +45 -44
  1032. data/ext/couchbase/couchbase/tracing/request_span.hxx +34 -34
  1033. data/ext/couchbase/couchbase/tracing/request_tracer.hxx +27 -25
  1034. data/ext/couchbase/couchbase/tracing_options.hxx +147 -142
  1035. data/ext/couchbase/couchbase/transactions/async_attempt_context.hxx +149 -115
  1036. data/ext/couchbase/couchbase/transactions/attempt_context.hxx +146 -95
  1037. data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +52 -80
  1038. data/ext/couchbase/couchbase/transactions/transaction_keyspace.hxx +33 -29
  1039. data/ext/couchbase/couchbase/transactions/transaction_options.hxx +101 -96
  1040. data/ext/couchbase/couchbase/transactions/transaction_query_options.hxx +228 -223
  1041. data/ext/couchbase/couchbase/transactions/transaction_query_result.hxx +11 -12
  1042. data/ext/couchbase/couchbase/transactions/transaction_result.hxx +2 -3
  1043. data/ext/couchbase/couchbase/transactions/transactions_cleanup_config.hxx +105 -104
  1044. data/ext/couchbase/couchbase/transactions/transactions_config.hxx +191 -187
  1045. data/ext/couchbase/couchbase/transactions/transactions_query_config.hxx +32 -32
  1046. data/ext/couchbase/couchbase/transactions.hxx +56 -37
  1047. data/ext/couchbase/couchbase/unfreeze_plan_search_index_options.hxx +11 -10
  1048. data/ext/couchbase/couchbase/unlock_options.hxx +25 -24
  1049. data/ext/couchbase/couchbase/update_bucket_options.hxx +9 -9
  1050. data/ext/couchbase/couchbase/update_collection_options.hxx +35 -34
  1051. data/ext/couchbase/couchbase/upsert_options.hxx +85 -80
  1052. data/ext/couchbase/couchbase/upsert_search_index_options.hxx +9 -9
  1053. data/ext/couchbase/couchbase/vector_query.hxx +82 -62
  1054. data/ext/couchbase/couchbase/vector_search.hxx +51 -47
  1055. data/ext/couchbase/couchbase/vector_search_options.hxx +45 -41
  1056. data/ext/couchbase/couchbase/wan_development_configuration_profile.hxx +13 -13
  1057. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +41 -41
  1058. data/ext/couchbase/couchbase/wildcard_query.hxx +42 -41
  1059. data/ext/couchbase/third_party/expected/include/tl/expected.hpp +1746 -1584
  1060. data/ext/couchbase/third_party/jsonsl/jsonsl.c +2664 -2638
  1061. data/ext/couchbase/third_party/jsonsl/jsonsl.h +359 -342
  1062. data/ext/couchbase.cxx +43 -9568
  1063. data/ext/extconf.rb +5 -0
  1064. data/ext/rcb_analytics.cxx +1195 -0
  1065. data/ext/rcb_analytics.hxx +29 -0
  1066. data/ext/rcb_backend.cxx +530 -0
  1067. data/ext/rcb_backend.hxx +46 -0
  1068. data/ext/rcb_buckets.cxx +624 -0
  1069. data/ext/rcb_buckets.hxx +29 -0
  1070. data/ext/rcb_collections.cxx +377 -0
  1071. data/ext/rcb_collections.hxx +29 -0
  1072. data/ext/rcb_crud.cxx +1544 -0
  1073. data/ext/rcb_crud.hxx +29 -0
  1074. data/ext/rcb_diagnostics.cxx +264 -0
  1075. data/ext/rcb_diagnostics.hxx +29 -0
  1076. data/ext/rcb_exceptions.cxx +963 -0
  1077. data/ext/rcb_exceptions.hxx +111 -0
  1078. data/ext/rcb_extras.cxx +394 -0
  1079. data/ext/rcb_extras.hxx +29 -0
  1080. data/ext/rcb_logger.cxx +319 -0
  1081. data/ext/rcb_logger.hxx +36 -0
  1082. data/ext/rcb_multi.cxx +343 -0
  1083. data/ext/rcb_multi.hxx +29 -0
  1084. data/ext/rcb_query.cxx +1316 -0
  1085. data/ext/rcb_query.hxx +29 -0
  1086. data/ext/rcb_range_scan.cxx +358 -0
  1087. data/ext/rcb_range_scan.hxx +29 -0
  1088. data/ext/rcb_search.cxx +1216 -0
  1089. data/ext/rcb_search.hxx +29 -0
  1090. data/ext/rcb_users.cxx +636 -0
  1091. data/ext/rcb_users.hxx +29 -0
  1092. data/ext/rcb_utils.cxx +590 -0
  1093. data/ext/rcb_utils.hxx +564 -0
  1094. data/ext/rcb_version.cxx +137 -0
  1095. data/ext/rcb_version.hxx +34 -0
  1096. data/ext/rcb_views.cxx +485 -0
  1097. data/ext/rcb_views.hxx +29 -0
  1098. data/lib/active_support/cache/couchbase_store.rb +4 -1
  1099. data/lib/couchbase/analytics_options.rb +2 -0
  1100. data/lib/couchbase/authenticator.rb +2 -0
  1101. data/lib/couchbase/binary_collection.rb +2 -0
  1102. data/lib/couchbase/binary_collection_options.rb +2 -0
  1103. data/lib/couchbase/bucket.rb +2 -0
  1104. data/lib/couchbase/cluster.rb +2 -0
  1105. data/lib/couchbase/collection.rb +3 -1
  1106. data/lib/couchbase/collection_options.rb +2 -0
  1107. data/lib/couchbase/config_profiles.rb +2 -0
  1108. data/lib/couchbase/configuration.rb +2 -0
  1109. data/lib/couchbase/datastructures/couchbase_list.rb +4 -4
  1110. data/lib/couchbase/datastructures/couchbase_map.rb +4 -4
  1111. data/lib/couchbase/datastructures/couchbase_queue.rb +4 -4
  1112. data/lib/couchbase/datastructures/couchbase_set.rb +4 -4
  1113. data/lib/couchbase/datastructures.rb +2 -0
  1114. data/lib/couchbase/diagnostics.rb +2 -0
  1115. data/lib/couchbase/errors.rb +46 -8
  1116. data/lib/couchbase/json_transcoder.rb +2 -0
  1117. data/lib/couchbase/key_value_scan.rb +2 -0
  1118. data/lib/couchbase/logger.rb +2 -0
  1119. data/lib/couchbase/management/analytics_index_manager.rb +2 -0
  1120. data/lib/couchbase/management/bucket_manager.rb +2 -0
  1121. data/lib/couchbase/management/collection_manager.rb +2 -0
  1122. data/lib/couchbase/management/collection_query_index_manager.rb +2 -0
  1123. data/lib/couchbase/management/query_index_manager.rb +2 -0
  1124. data/lib/couchbase/management/scope_search_index_manager.rb +2 -0
  1125. data/lib/couchbase/management/search_index_manager.rb +2 -0
  1126. data/lib/couchbase/management/user_manager.rb +2 -0
  1127. data/lib/couchbase/management/view_index_manager.rb +2 -0
  1128. data/lib/couchbase/management.rb +2 -0
  1129. data/lib/couchbase/mutation_state.rb +2 -0
  1130. data/lib/couchbase/options.rb +2 -0
  1131. data/lib/couchbase/protostellar/request_generator/kv.rb +1 -1
  1132. data/lib/couchbase/query_options.rb +2 -0
  1133. data/lib/couchbase/railtie.rb +2 -0
  1134. data/lib/couchbase/raw_binary_transcoder.rb +2 -0
  1135. data/lib/couchbase/raw_json_transcoder.rb +2 -0
  1136. data/lib/couchbase/raw_string_transcoder.rb +2 -0
  1137. data/lib/couchbase/scope.rb +2 -0
  1138. data/lib/couchbase/search_options.rb +91 -63
  1139. data/lib/couchbase/subdoc.rb +5 -3
  1140. data/lib/couchbase/transcoder_flags.rb +2 -0
  1141. data/lib/couchbase/utils/generic_logger_adapter.rb +3 -1
  1142. data/lib/couchbase/utils/stdlib_logger_adapter.rb +2 -0
  1143. data/lib/couchbase/utils/time.rb +3 -1
  1144. data/lib/couchbase/utils.rb +2 -0
  1145. data/lib/couchbase/version.rb +3 -1
  1146. data/lib/couchbase/view_options.rb +2 -0
  1147. data/lib/couchbase.rb +2 -0
  1148. data/lib/rails/generators/couchbase/config/config_generator.rb +2 -0
  1149. metadata +83 -26
  1150. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +0 -113
  1151. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +0 -60
  1152. data/ext/couchbase/core/impl/manager_error_context.cxx +0 -100
  1153. data/ext/couchbase/core/impl/search_error_context.cxx +0 -147
  1154. data/ext/couchbase/couchbase/analytics_error_context.hxx +0 -143
  1155. data/ext/couchbase/couchbase/fmt/key_value_error_map_attribute.hxx +0 -100
  1156. data/ext/couchbase/couchbase/fmt/key_value_status_code.hxx +0 -269
  1157. data/ext/couchbase/couchbase/key_value_error_context.hxx +0 -229
  1158. data/ext/couchbase/couchbase/key_value_error_map_attribute.hxx +0 -136
  1159. data/ext/couchbase/couchbase/key_value_error_map_info.hxx +0 -138
  1160. data/ext/couchbase/couchbase/key_value_extended_error_info.hxx +0 -86
  1161. data/ext/couchbase/couchbase/key_value_status_code.hxx +0 -109
  1162. data/ext/couchbase/couchbase/manager_error_context.hxx +0 -111
  1163. data/ext/couchbase/couchbase/query_error_context.hxx +0 -145
  1164. data/ext/couchbase/couchbase/search_error_context.hxx +0 -138
  1165. data/ext/couchbase/couchbase/subdocument_error_context.hxx +0 -147
  1166. data/ext/couchbase/couchbase/transaction_op_error_context.hxx +0 -76
@@ -30,10 +30,10 @@ namespace internal
30
30
  #include <bcrypt.h>
31
31
 
32
32
  struct HeapAllocDeleter {
33
- void operator()(PBYTE bytes)
34
- {
35
- HeapFree(GetProcessHeap(), 0, bytes);
36
- }
33
+ void operator()(PBYTE bytes)
34
+ {
35
+ HeapFree(GetProcessHeap(), 0, bytes);
36
+ }
37
37
  };
38
38
 
39
39
  using uniqueHeapPtr = std::unique_ptr<BYTE, HeapAllocDeleter>;
@@ -41,260 +41,289 @@ using uniqueHeapPtr = std::unique_ptr<BYTE, HeapAllocDeleter>;
41
41
  static inline std::string
42
42
  hash(std::string_view key, std::string_view data, LPCWSTR algorithm, int flags)
43
43
  {
44
- BCRYPT_ALG_HANDLE hAlg;
45
- NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlg, algorithm, nullptr, flags);
46
- if (status < 0) {
47
- throw std::runtime_error("digest: BCryptOpenAlgorithmProvider return: " + std::to_string(status));
48
- }
49
-
50
- DWORD pcbResult = 0;
51
- DWORD cbHashObject = 0;
52
-
53
- // calculate the size of the buffer to hold the hash object
54
- status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH, reinterpret_cast<PBYTE>(&cbHashObject), sizeof(DWORD), &pcbResult, 0);
55
- if (status < 0) {
56
- BCryptCloseAlgorithmProvider(hAlg, 0);
57
- throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
58
- }
59
-
60
- // calculate the length of the hash
61
- DWORD cbHash = 0;
62
- status = BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH, reinterpret_cast<PBYTE>(&cbHash), sizeof(DWORD), &pcbResult, 0);
63
- if (status < 0) {
64
- BCryptCloseAlgorithmProvider(hAlg, 0);
65
- throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
66
- }
67
-
68
- // allocate the hash object on the heap
69
- uniqueHeapPtr pbHashObject(static_cast<PBYTE>(HeapAlloc(GetProcessHeap(), 0, cbHashObject)));
70
- if (!pbHashObject) {
71
- BCryptCloseAlgorithmProvider(hAlg, 0);
72
- throw std::bad_alloc();
73
- }
74
-
75
- std::string ret;
76
- ret.resize(cbHash);
77
-
78
- // create the hash
79
- BCRYPT_HASH_HANDLE hHash;
80
- status = BCryptCreateHash(hAlg, &hHash, pbHashObject.get(), cbHashObject, (PUCHAR)key.data(), static_cast<ULONG>(key.size()), 0);
81
- if (status < 0) {
82
- BCryptCloseAlgorithmProvider(hAlg, 0);
83
- throw std::runtime_error("digest: BCryptCreateHash return: " + std::to_string(status));
84
- }
85
-
86
- status = BCryptHashData(hHash, (PBYTE)data.data(), static_cast<ULONG>(data.size()), 0);
87
- if (status < 0) {
88
- BCryptCloseAlgorithmProvider(hAlg, 0);
89
- BCryptDestroyHash(hHash);
90
- throw std::runtime_error("digest: BCryptHashData return: " + std::to_string(status));
91
- }
44
+ BCRYPT_ALG_HANDLE hAlg;
45
+ NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlg, algorithm, nullptr, flags);
46
+ if (status < 0) {
47
+ throw std::runtime_error("digest: BCryptOpenAlgorithmProvider return: " +
48
+ std::to_string(status));
49
+ }
50
+
51
+ DWORD pcbResult = 0;
52
+ DWORD cbHashObject = 0;
53
+
54
+ // calculate the size of the buffer to hold the hash object
55
+ status = BCryptGetProperty(hAlg,
56
+ BCRYPT_OBJECT_LENGTH,
57
+ reinterpret_cast<PBYTE>(&cbHashObject),
58
+ sizeof(DWORD),
59
+ &pcbResult,
60
+ 0);
61
+ if (status < 0) {
62
+ BCryptCloseAlgorithmProvider(hAlg, 0);
63
+ throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
64
+ }
65
+
66
+ // calculate the length of the hash
67
+ DWORD cbHash = 0;
68
+ status = BCryptGetProperty(
69
+ hAlg, BCRYPT_HASH_LENGTH, reinterpret_cast<PBYTE>(&cbHash), sizeof(DWORD), &pcbResult, 0);
70
+ if (status < 0) {
71
+ BCryptCloseAlgorithmProvider(hAlg, 0);
72
+ throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
73
+ }
92
74
 
93
- status = BCryptFinishHash(hHash, reinterpret_cast<std::uint8_t*>(ret.data()), cbHash, 0);
75
+ // allocate the hash object on the heap
76
+ uniqueHeapPtr pbHashObject(static_cast<PBYTE>(HeapAlloc(GetProcessHeap(), 0, cbHashObject)));
77
+ if (!pbHashObject) {
78
+ BCryptCloseAlgorithmProvider(hAlg, 0);
79
+ throw std::bad_alloc();
80
+ }
81
+
82
+ std::string ret;
83
+ ret.resize(cbHash);
84
+
85
+ // create the hash
86
+ BCRYPT_HASH_HANDLE hHash;
87
+ status = BCryptCreateHash(hAlg,
88
+ &hHash,
89
+ pbHashObject.get(),
90
+ cbHashObject,
91
+ (PUCHAR)key.data(),
92
+ static_cast<ULONG>(key.size()),
93
+ 0);
94
+ if (status < 0) {
95
+ BCryptCloseAlgorithmProvider(hAlg, 0);
96
+ throw std::runtime_error("digest: BCryptCreateHash return: " + std::to_string(status));
97
+ }
94
98
 
95
- // Release resources
99
+ status = BCryptHashData(hHash, (PBYTE)data.data(), static_cast<ULONG>(data.size()), 0);
100
+ if (status < 0) {
96
101
  BCryptCloseAlgorithmProvider(hAlg, 0);
97
102
  BCryptDestroyHash(hHash);
103
+ throw std::runtime_error("digest: BCryptHashData return: " + std::to_string(status));
104
+ }
98
105
 
99
- if (status < 0) {
100
- throw std::runtime_error("digest: BCryptFinishHash return: " + std::to_string(status));
101
- }
106
+ status = BCryptFinishHash(hHash, reinterpret_cast<std::uint8_t*>(ret.data()), cbHash, 0);
102
107
 
103
- return ret;
108
+ // Release resources
109
+ BCryptCloseAlgorithmProvider(hAlg, 0);
110
+ BCryptDestroyHash(hHash);
111
+
112
+ if (status < 0) {
113
+ throw std::runtime_error("digest: BCryptFinishHash return: " + std::to_string(status));
114
+ }
115
+
116
+ return ret;
104
117
  }
105
118
 
106
119
  static std::string
107
120
  HMAC_SHA1(std::string_view key, std::string_view data)
108
121
  {
109
- return hash(key, data, BCRYPT_SHA1_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
122
+ return hash(key, data, BCRYPT_SHA1_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
110
123
  }
111
124
 
112
125
  static std::string
113
126
  HMAC_SHA256(std::string_view key, std::string_view data)
114
127
  {
115
- return hash(key, data, BCRYPT_SHA256_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
128
+ return hash(key, data, BCRYPT_SHA256_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
116
129
  }
117
130
 
118
131
  static std::string
119
132
  HMAC_SHA512(std::string_view key, std::string_view data)
120
133
  {
121
- return hash(key, data, BCRYPT_SHA512_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
134
+ return hash(key, data, BCRYPT_SHA512_ALGORITHM, BCRYPT_ALG_HANDLE_HMAC_FLAG);
122
135
  }
123
136
 
124
137
  static inline std::string
125
- PBKDF2(const std::string& pass, std::string_view salt, unsigned int iterationCount, LPCWSTR algorithm)
138
+ PBKDF2(const std::string& pass,
139
+ std::string_view salt,
140
+ unsigned int iterationCount,
141
+ LPCWSTR algorithm)
126
142
  {
127
- // open an algorithm handle
128
- BCRYPT_ALG_HANDLE hAlg;
129
- NTSTATUS status;
130
-
131
- status = BCryptOpenAlgorithmProvider(&hAlg, algorithm, nullptr, BCRYPT_ALG_HANDLE_HMAC_FLAG);
132
- if (status < 0) {
133
- throw std::runtime_error("digest: BCryptOpenAlgorithmProvider return: " + std::to_string(status));
134
- }
135
-
136
- DWORD pcbResult = 0;
137
-
138
- // calculate the length of the hash
139
- DWORD cbHash = 0;
140
- status = BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH, (PBYTE)&cbHash, sizeof(DWORD), &pcbResult, 0);
141
- if (status < 0) {
142
- BCryptCloseAlgorithmProvider(hAlg, 0);
143
- throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
144
- }
145
-
146
- std::string ret;
147
- ret.resize(cbHash);
148
-
149
- status = BCryptDeriveKeyPBKDF2(hAlg,
150
- (PUCHAR)pass.data(),
151
- ULONG(pass.size()),
152
- (PUCHAR)salt.data(),
153
- ULONG(salt.size()),
154
- iterationCount,
155
- (PUCHAR)ret.data(),
156
- ULONG(ret.size()),
157
- 0);
158
-
159
- // Release resources
143
+ // open an algorithm handle
144
+ BCRYPT_ALG_HANDLE hAlg;
145
+ NTSTATUS status;
146
+
147
+ status = BCryptOpenAlgorithmProvider(&hAlg, algorithm, nullptr, BCRYPT_ALG_HANDLE_HMAC_FLAG);
148
+ if (status < 0) {
149
+ throw std::runtime_error("digest: BCryptOpenAlgorithmProvider return: " +
150
+ std::to_string(status));
151
+ }
152
+
153
+ DWORD pcbResult = 0;
154
+
155
+ // calculate the length of the hash
156
+ DWORD cbHash = 0;
157
+ status =
158
+ BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH, (PBYTE)&cbHash, sizeof(DWORD), &pcbResult, 0);
159
+ if (status < 0) {
160
160
  BCryptCloseAlgorithmProvider(hAlg, 0);
161
-
162
- if (status < 0) {
163
- throw std::runtime_error("digest: BCryptDeriveKeyPBKDF2 return: " + std::to_string(status));
164
- }
165
-
166
- return ret;
161
+ throw std::runtime_error("digest: BCryptGetProperty return: " + std::to_string(status));
162
+ }
163
+
164
+ std::string ret;
165
+ ret.resize(cbHash);
166
+
167
+ status = BCryptDeriveKeyPBKDF2(hAlg,
168
+ (PUCHAR)pass.data(),
169
+ ULONG(pass.size()),
170
+ (PUCHAR)salt.data(),
171
+ ULONG(salt.size()),
172
+ iterationCount,
173
+ (PUCHAR)ret.data(),
174
+ ULONG(ret.size()),
175
+ 0);
176
+
177
+ // Release resources
178
+ BCryptCloseAlgorithmProvider(hAlg, 0);
179
+
180
+ if (status < 0) {
181
+ throw std::runtime_error("digest: BCryptDeriveKeyPBKDF2 return: " + std::to_string(status));
182
+ }
183
+
184
+ return ret;
167
185
  }
168
186
 
169
187
  static std::string
170
188
  PBKDF2_HMAC_SHA1(const std::string& pass, std::string_view salt, unsigned int iterationCount)
171
189
  {
172
- return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA1_ALGORITHM);
190
+ return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA1_ALGORITHM);
173
191
  }
174
192
 
175
193
  static std::string
176
194
  PBKDF2_HMAC_SHA256(const std::string& pass, std::string_view salt, unsigned int iterationCount)
177
195
  {
178
- return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA256_ALGORITHM);
196
+ return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA256_ALGORITHM);
179
197
  }
180
198
 
181
199
  static std::string
182
200
  PBKDF2_HMAC_SHA512(const std::string& pass, std::string_view salt, unsigned int iterationCount)
183
201
  {
184
- return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA512_ALGORITHM);
202
+ return PBKDF2(pass, salt, iterationCount, BCRYPT_SHA512_ALGORITHM);
185
203
  }
186
204
 
187
205
  static std::string
188
206
  digest_sha1(std::string_view data)
189
207
  {
190
- return hash({}, data, BCRYPT_SHA1_ALGORITHM, 0);
208
+ return hash({}, data, BCRYPT_SHA1_ALGORITHM, 0);
191
209
  }
192
210
 
193
211
  static std::string
194
212
  digest_sha256(std::string_view data)
195
213
  {
196
- return hash({}, data, BCRYPT_SHA256_ALGORITHM, 0);
214
+ return hash({}, data, BCRYPT_SHA256_ALGORITHM, 0);
197
215
  }
198
216
 
199
217
  static std::string
200
218
  digest_sha512(std::string_view data)
201
219
  {
202
- return hash({}, data, BCRYPT_SHA512_ALGORITHM, 0);
220
+ return hash({}, data, BCRYPT_SHA512_ALGORITHM, 0);
203
221
  }
204
222
 
205
223
  std::string
206
224
  AES_256_cbc(bool encrypt, std::string_view key, std::string_view iv, std::string_view data)
207
225
  {
208
- BCRYPT_ALG_HANDLE hAlg;
209
- NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM, nullptr, 0);
210
-
211
- if (status < 0) {
212
- throw std::runtime_error("encrypt: BCryptOpenAlgorithmProvider() return: " + std::to_string(status));
213
- }
214
-
215
- DWORD cbData = 0;
216
- DWORD cbKeyObject = 0;
226
+ BCRYPT_ALG_HANDLE hAlg;
227
+ NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM, nullptr, 0);
217
228
 
218
- // Calculate the size of the buffer to hold the KeyObject.
219
- status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH, (PBYTE)&cbKeyObject, sizeof(DWORD), &cbData, 0);
220
- if (status < 0) {
221
- BCryptCloseAlgorithmProvider(hAlg, 0);
222
- throw std::runtime_error("encrypt: BCryptGetProperty() return: " + std::to_string(status));
223
- }
229
+ if (status < 0) {
230
+ throw std::runtime_error("encrypt: BCryptOpenAlgorithmProvider() return: " +
231
+ std::to_string(status));
232
+ }
224
233
 
225
- // Allocate the key object on the heap.
226
- uniqueHeapPtr pbKeyObject((PBYTE)HeapAlloc(GetProcessHeap(), 0, cbKeyObject));
227
- if (!pbKeyObject) {
228
- BCryptCloseAlgorithmProvider(hAlg, 0);
229
- throw std::bad_alloc();
230
- }
231
-
232
- status = BCryptSetProperty(hAlg, BCRYPT_CHAINING_MODE, (PBYTE)BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
233
- if (status < 0) {
234
- BCryptCloseAlgorithmProvider(hAlg, 0);
235
- throw std::runtime_error("encrypt: BCryptSetProperty() return: " + std::to_string(status));
236
- }
237
-
238
- // Generate the key from supplied input key bytes.
239
- BCRYPT_KEY_HANDLE hKey;
240
- status = BCryptGenerateSymmetricKey(hAlg, &hKey, pbKeyObject.get(), cbKeyObject, (PBYTE)key.data(), ULONG(key.size()), 0);
241
- if (status < 0) {
242
- BCryptCloseAlgorithmProvider(hAlg, 0);
243
- throw std::runtime_error("encrypt: BCryptGenerateSymmetricKey() return: " + std::to_string(status));
244
- }
245
-
246
- // For some reason the API will modify the input vector.. just create a
247
- // copy.. it's small anyway
248
- std::string civ(iv.begin(), iv.end());
249
-
250
- std::string ret;
251
- ret.resize(data.size() + iv.size());
252
- if (encrypt) {
253
- status = BCryptEncrypt(hKey,
254
- (PUCHAR)data.data(),
255
- ULONG(data.size()),
256
- nullptr,
257
- (PBYTE)civ.data(),
258
- ULONG(civ.size()),
259
- reinterpret_cast<std::uint8_t*>(ret.data()),
260
- ULONG(ret.size()),
261
- &cbData,
262
- BCRYPT_BLOCK_PADDING);
263
- } else {
264
- status = BCryptDecrypt(hKey,
265
- (PUCHAR)data.data(),
266
- ULONG(data.size()),
267
- nullptr,
268
- (PBYTE)civ.data(),
269
- ULONG(civ.size()),
270
- reinterpret_cast<std::uint8_t*>(ret.data()),
271
- ULONG(ret.size()),
272
- &cbData,
273
- BCRYPT_BLOCK_PADDING);
274
- }
234
+ DWORD cbData = 0;
235
+ DWORD cbKeyObject = 0;
275
236
 
237
+ // Calculate the size of the buffer to hold the KeyObject.
238
+ status =
239
+ BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH, (PBYTE)&cbKeyObject, sizeof(DWORD), &cbData, 0);
240
+ if (status < 0) {
276
241
  BCryptCloseAlgorithmProvider(hAlg, 0);
277
- BCryptDestroyKey(hKey);
242
+ throw std::runtime_error("encrypt: BCryptGetProperty() return: " + std::to_string(status));
243
+ }
278
244
 
279
- if (status < 0) {
280
- throw std::runtime_error("encrypt: BCryptEncrypt() return: " + std::to_string(status));
281
- }
282
-
283
- ret.resize(cbData);
245
+ // Allocate the key object on the heap.
246
+ uniqueHeapPtr pbKeyObject((PBYTE)HeapAlloc(GetProcessHeap(), 0, cbKeyObject));
247
+ if (!pbKeyObject) {
248
+ BCryptCloseAlgorithmProvider(hAlg, 0);
249
+ throw std::bad_alloc();
250
+ }
284
251
 
285
- return ret;
252
+ status = BCryptSetProperty(
253
+ hAlg, BCRYPT_CHAINING_MODE, (PBYTE)BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
254
+ if (status < 0) {
255
+ BCryptCloseAlgorithmProvider(hAlg, 0);
256
+ throw std::runtime_error("encrypt: BCryptSetProperty() return: " + std::to_string(status));
257
+ }
258
+
259
+ // Generate the key from supplied input key bytes.
260
+ BCRYPT_KEY_HANDLE hKey;
261
+ status = BCryptGenerateSymmetricKey(
262
+ hAlg, &hKey, pbKeyObject.get(), cbKeyObject, (PBYTE)key.data(), ULONG(key.size()), 0);
263
+ if (status < 0) {
264
+ BCryptCloseAlgorithmProvider(hAlg, 0);
265
+ throw std::runtime_error("encrypt: BCryptGenerateSymmetricKey() return: " +
266
+ std::to_string(status));
267
+ }
268
+
269
+ // For some reason the API will modify the input vector.. just create a
270
+ // copy.. it's small anyway
271
+ std::string civ(iv.begin(), iv.end());
272
+
273
+ std::string ret;
274
+ ret.resize(data.size() + iv.size());
275
+ if (encrypt) {
276
+ status = BCryptEncrypt(hKey,
277
+ (PUCHAR)data.data(),
278
+ ULONG(data.size()),
279
+ nullptr,
280
+ (PBYTE)civ.data(),
281
+ ULONG(civ.size()),
282
+ reinterpret_cast<std::uint8_t*>(ret.data()),
283
+ ULONG(ret.size()),
284
+ &cbData,
285
+ BCRYPT_BLOCK_PADDING);
286
+ } else {
287
+ status = BCryptDecrypt(hKey,
288
+ (PUCHAR)data.data(),
289
+ ULONG(data.size()),
290
+ nullptr,
291
+ (PBYTE)civ.data(),
292
+ ULONG(civ.size()),
293
+ reinterpret_cast<std::uint8_t*>(ret.data()),
294
+ ULONG(ret.size()),
295
+ &cbData,
296
+ BCRYPT_BLOCK_PADDING);
297
+ }
298
+
299
+ BCryptCloseAlgorithmProvider(hAlg, 0);
300
+ BCryptDestroyKey(hKey);
301
+
302
+ if (status < 0) {
303
+ throw std::runtime_error("encrypt: BCryptEncrypt() return: " + std::to_string(status));
304
+ }
305
+
306
+ ret.resize(cbData);
307
+
308
+ return ret;
286
309
  }
287
310
 
288
311
  std::string
289
- encrypt(const couchbase::core::crypto::Cipher /* cipher */, std::string_view key, std::string_view iv, std::string_view data)
312
+ encrypt(const couchbase::core::crypto::Cipher /* cipher */,
313
+ std::string_view key,
314
+ std::string_view iv,
315
+ std::string_view data)
290
316
  {
291
- return AES_256_cbc(true, key, iv, data);
317
+ return AES_256_cbc(true, key, iv, data);
292
318
  }
293
319
 
294
320
  std::string
295
- decrypt(const couchbase::core::crypto::Cipher /* cipher */, std::string_view key, std::string_view iv, std::string_view data)
321
+ decrypt(const couchbase::core::crypto::Cipher /* cipher */,
322
+ std::string_view key,
323
+ std::string_view iv,
324
+ std::string_view data)
296
325
  {
297
- return AES_256_cbc(false, key, iv, data);
326
+ return AES_256_cbc(false, key, iv, data);
298
327
  }
299
328
 
300
329
  #elif defined(__APPLE__)
@@ -307,120 +336,140 @@ decrypt(const couchbase::core::crypto::Cipher /* cipher */, std::string_view key
307
336
  static std::string
308
337
  HMAC_SHA1(std::string_view key, std::string_view data)
309
338
  {
310
- std::string ret;
311
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
312
- CCHmac(kCCHmacAlgSHA1, key.data(), key.size(), data.data(), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
313
- return ret;
339
+ std::string ret;
340
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
341
+ CCHmac(kCCHmacAlgSHA1,
342
+ key.data(),
343
+ key.size(),
344
+ data.data(),
345
+ data.size(),
346
+ reinterpret_cast<std::uint8_t*>(ret.data()));
347
+ return ret;
314
348
  }
315
349
 
316
350
  static std::string
317
351
  HMAC_SHA256(std::string_view key, std::string_view data)
318
352
  {
319
- std::string ret;
320
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
321
- CCHmac(kCCHmacAlgSHA256, key.data(), key.size(), data.data(), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
322
- return ret;
353
+ std::string ret;
354
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
355
+ CCHmac(kCCHmacAlgSHA256,
356
+ key.data(),
357
+ key.size(),
358
+ data.data(),
359
+ data.size(),
360
+ reinterpret_cast<std::uint8_t*>(ret.data()));
361
+ return ret;
323
362
  }
324
363
 
325
364
  static std::string
326
365
  HMAC_SHA512(std::string_view key, std::string_view data)
327
366
  {
328
- std::string ret;
329
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
330
- CCHmac(kCCHmacAlgSHA512, key.data(), key.size(), data.data(), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
331
- return ret;
367
+ std::string ret;
368
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
369
+ CCHmac(kCCHmacAlgSHA512,
370
+ key.data(),
371
+ key.size(),
372
+ data.data(),
373
+ data.size(),
374
+ reinterpret_cast<std::uint8_t*>(ret.data()));
375
+ return ret;
332
376
  }
333
377
 
334
378
  static std::string
335
379
  PBKDF2_HMAC_SHA1(const std::string& pass, std::string_view salt, unsigned int iterationCount)
336
380
  {
337
- std::string ret;
338
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
339
- auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
340
- pass.data(),
341
- pass.size(),
342
- reinterpret_cast<const std::uint8_t*>(salt.data()),
343
- salt.size(),
344
- kCCPRFHmacAlgSHA1,
345
- iterationCount,
346
- reinterpret_cast<std::uint8_t*>(ret.data()),
347
- ret.size());
348
-
349
- if (err != 0) {
350
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA1): CCKeyDerivationPBKDF failed: " + std::to_string(err));
351
- }
352
- return ret;
381
+ std::string ret;
382
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
383
+ auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
384
+ pass.data(),
385
+ pass.size(),
386
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
387
+ salt.size(),
388
+ kCCPRFHmacAlgSHA1,
389
+ iterationCount,
390
+ reinterpret_cast<std::uint8_t*>(ret.data()),
391
+ ret.size());
392
+
393
+ if (err != 0) {
394
+ throw std::runtime_error(
395
+ "couchbase::core::crypto::PBKDF2_HMAC(SHA1): CCKeyDerivationPBKDF failed: " +
396
+ std::to_string(err));
397
+ }
398
+ return ret;
353
399
  }
354
400
 
355
401
  static std::string
356
402
  PBKDF2_HMAC_SHA256(const std::string& pass, std::string_view salt, unsigned int iterationCount)
357
403
  {
358
- std::string ret;
359
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
360
- auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
361
- pass.data(),
362
- pass.size(),
363
- reinterpret_cast<const std::uint8_t*>(salt.data()),
364
- salt.size(),
365
- kCCPRFHmacAlgSHA256,
366
- iterationCount,
367
- reinterpret_cast<std::uint8_t*>(ret.data()),
368
- ret.size());
369
- if (err != 0) {
370
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA256): CCKeyDerivationPBKDF "
371
- "failed: " +
372
- std::to_string(err));
373
- }
374
- return ret;
404
+ std::string ret;
405
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
406
+ auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
407
+ pass.data(),
408
+ pass.size(),
409
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
410
+ salt.size(),
411
+ kCCPRFHmacAlgSHA256,
412
+ iterationCount,
413
+ reinterpret_cast<std::uint8_t*>(ret.data()),
414
+ ret.size());
415
+ if (err != 0) {
416
+ throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA256): CCKeyDerivationPBKDF "
417
+ "failed: " +
418
+ std::to_string(err));
419
+ }
420
+ return ret;
375
421
  }
376
422
 
377
423
  static std::string
378
424
  PBKDF2_HMAC_SHA512(const std::string& pass, std::string_view salt, unsigned int iterationCount)
379
425
  {
380
- std::string ret;
381
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
382
- auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
383
- pass.data(),
384
- pass.size(),
385
- reinterpret_cast<const std::uint8_t*>(salt.data()),
386
- salt.size(),
387
- kCCPRFHmacAlgSHA512,
388
- iterationCount,
389
- reinterpret_cast<std::uint8_t*>(ret.data()),
390
- ret.size());
391
- if (err != 0) {
392
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA512): CCKeyDerivationPBKDF "
393
- "failed: " +
394
- std::to_string(err));
395
- }
396
- return ret;
426
+ std::string ret;
427
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
428
+ auto err = CCKeyDerivationPBKDF(kCCPBKDF2,
429
+ pass.data(),
430
+ pass.size(),
431
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
432
+ salt.size(),
433
+ kCCPRFHmacAlgSHA512,
434
+ iterationCount,
435
+ reinterpret_cast<std::uint8_t*>(ret.data()),
436
+ ret.size());
437
+ if (err != 0) {
438
+ throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA512): CCKeyDerivationPBKDF "
439
+ "failed: " +
440
+ std::to_string(err));
441
+ }
442
+ return ret;
397
443
  }
398
444
 
399
445
  static std::string
400
446
  digest_sha1(std::string_view data)
401
447
  {
402
- std::string ret;
403
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
404
- CC_SHA1(data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
405
- return ret;
448
+ std::string ret;
449
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
450
+ CC_SHA1(
451
+ data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
452
+ return ret;
406
453
  }
407
454
 
408
455
  static std::string
409
456
  digest_sha256(std::string_view data)
410
457
  {
411
- std::string ret;
412
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
413
- CC_SHA256(data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
414
- return ret;
458
+ std::string ret;
459
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
460
+ CC_SHA256(
461
+ data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
462
+ return ret;
415
463
  }
416
464
 
417
465
  static std::string
418
466
  digest_sha512(std::string_view data)
419
467
  {
420
- std::string ret;
421
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
422
- CC_SHA512(data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
423
- return ret;
468
+ std::string ret;
469
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
470
+ CC_SHA512(
471
+ data.data(), static_cast<CC_LONG>(data.size()), reinterpret_cast<std::uint8_t*>(ret.data()));
472
+ return ret;
424
473
  }
425
474
 
426
475
  /**
@@ -430,85 +479,99 @@ digest_sha512(std::string_view data)
430
479
  * Currently only AES_256_cbc is supported
431
480
  */
432
481
  static void
433
- validateEncryptionCipher(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv)
434
- {
435
- switch (cipher) {
436
- case couchbase::core::crypto::Cipher::AES_256_cbc:
437
- if (key.size() != kCCKeySizeAES256) {
438
- throw std::invalid_argument("couchbase::core::crypto::validateEncryptionCipher: Cipher requires a "
439
- "key "
440
- "length of " +
441
- std::to_string(kCCKeySizeAES256) + " provided key with length " + std::to_string(key.size()));
442
- }
443
-
444
- if (iv.size() != 16) {
445
- throw std::invalid_argument("couchbase::core::crypto::validateEncryptionCipher: Cipher requires a "
446
- "iv "
447
- "length of 16 provided iv with length " +
448
- std::to_string(iv.size()));
449
- }
450
- return;
451
- }
452
-
453
- throw std::invalid_argument("couchbase::core::crypto::validateEncryptionCipher: Unknown Cipher " + std::to_string(int(cipher)));
482
+ validateEncryptionCipher(const couchbase::core::crypto::Cipher cipher,
483
+ std::string_view key,
484
+ std::string_view iv)
485
+ {
486
+ switch (cipher) {
487
+ case couchbase::core::crypto::Cipher::AES_256_cbc:
488
+ if (key.size() != kCCKeySizeAES256) {
489
+ throw std::invalid_argument(
490
+ "couchbase::core::crypto::validateEncryptionCipher: Cipher requires a "
491
+ "key "
492
+ "length of " +
493
+ std::to_string(kCCKeySizeAES256) + " provided key with length " +
494
+ std::to_string(key.size()));
495
+ }
496
+
497
+ if (iv.size() != 16) {
498
+ throw std::invalid_argument(
499
+ "couchbase::core::crypto::validateEncryptionCipher: Cipher requires a "
500
+ "iv "
501
+ "length of 16 provided iv with length " +
502
+ std::to_string(iv.size()));
503
+ }
504
+ return;
505
+ }
506
+
507
+ throw std::invalid_argument("couchbase::core::crypto::validateEncryptionCipher: Unknown Cipher " +
508
+ std::to_string(int(cipher)));
454
509
  }
455
510
 
456
511
  std::string
457
- encrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
458
- {
459
- size_t outputsize = 0;
460
- std::string ret;
461
- ret.resize(data.size() + kCCBlockSizeAES128);
462
-
463
- validateEncryptionCipher(cipher, key, iv);
464
-
465
- auto status = CCCrypt(kCCEncrypt,
466
- kCCAlgorithmAES128,
467
- kCCOptionPKCS7Padding,
468
- key.data(),
469
- kCCKeySizeAES256,
470
- iv.data(),
471
- data.data(),
472
- data.size(),
473
- reinterpret_cast<std::uint8_t*>(ret.data()),
474
- ret.size(),
475
- &outputsize);
476
-
477
- if (status != kCCSuccess) {
478
- throw std::runtime_error("couchbase::core::crypto::encrypt: CCCrypt failed: " + std::to_string(status));
479
- }
480
-
481
- ret.resize(outputsize);
482
- return ret;
512
+ encrypt(const couchbase::core::crypto::Cipher cipher,
513
+ std::string_view key,
514
+ std::string_view iv,
515
+ std::string_view data)
516
+ {
517
+ size_t outputsize = 0;
518
+ std::string ret;
519
+ ret.resize(data.size() + kCCBlockSizeAES128);
520
+
521
+ validateEncryptionCipher(cipher, key, iv);
522
+
523
+ auto status = CCCrypt(kCCEncrypt,
524
+ kCCAlgorithmAES128,
525
+ kCCOptionPKCS7Padding,
526
+ key.data(),
527
+ kCCKeySizeAES256,
528
+ iv.data(),
529
+ data.data(),
530
+ data.size(),
531
+ reinterpret_cast<std::uint8_t*>(ret.data()),
532
+ ret.size(),
533
+ &outputsize);
534
+
535
+ if (status != kCCSuccess) {
536
+ throw std::runtime_error("couchbase::core::crypto::encrypt: CCCrypt failed: " +
537
+ std::to_string(status));
538
+ }
539
+
540
+ ret.resize(outputsize);
541
+ return ret;
483
542
  }
484
543
 
485
544
  std::string
486
- decrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
487
- {
488
- size_t outputsize = 0;
489
- std::string ret;
490
- ret.resize(data.size());
491
-
492
- validateEncryptionCipher(cipher, key, iv);
493
-
494
- auto status = CCCrypt(kCCDecrypt,
495
- kCCAlgorithmAES128,
496
- kCCOptionPKCS7Padding,
497
- key.data(),
498
- kCCKeySizeAES256,
499
- iv.data(),
500
- data.data(),
501
- data.size(),
502
- reinterpret_cast<std::uint8_t*>(ret.data()),
503
- ret.size(),
504
- &outputsize);
505
-
506
- if (status != kCCSuccess) {
507
- throw std::runtime_error("couchbase::core::crypto::decrypt: CCCrypt failed: " + std::to_string(status));
508
- }
509
-
510
- ret.resize(outputsize);
511
- return ret;
545
+ decrypt(const couchbase::core::crypto::Cipher cipher,
546
+ std::string_view key,
547
+ std::string_view iv,
548
+ std::string_view data)
549
+ {
550
+ size_t outputsize = 0;
551
+ std::string ret;
552
+ ret.resize(data.size());
553
+
554
+ validateEncryptionCipher(cipher, key, iv);
555
+
556
+ auto status = CCCrypt(kCCDecrypt,
557
+ kCCAlgorithmAES128,
558
+ kCCOptionPKCS7Padding,
559
+ key.data(),
560
+ kCCKeySizeAES256,
561
+ iv.data(),
562
+ data.data(),
563
+ data.size(),
564
+ reinterpret_cast<std::uint8_t*>(ret.data()),
565
+ ret.size(),
566
+ &outputsize);
567
+
568
+ if (status != kCCSuccess) {
569
+ throw std::runtime_error("couchbase::core::crypto::decrypt: CCCrypt failed: " +
570
+ std::to_string(status));
571
+ }
572
+
573
+ ret.resize(outputsize);
574
+ return ret;
512
575
  }
513
576
 
514
577
  #else
@@ -523,195 +586,205 @@ decrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std:
523
586
  static std::string
524
587
  HMAC_SHA1(std::string_view key, std::string_view data)
525
588
  {
526
- std::string ret;
527
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
589
+ std::string ret;
590
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
528
591
 
529
592
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
530
- auto key_size = key.size();
593
+ auto key_size = key.size();
531
594
  #else
532
- auto key_size = static_cast<int>(key.size());
595
+ auto key_size = static_cast<int>(key.size());
533
596
  #endif
534
597
 
535
- if (HMAC(EVP_sha1(),
536
- key.data(),
537
- key_size,
538
- reinterpret_cast<const std::uint8_t*>(data.data()),
539
- data.size(),
540
- reinterpret_cast<std::uint8_t*>(ret.data()),
541
- nullptr) == nullptr) {
542
- throw std::runtime_error("couchbase::core::crypto::HMAC(SHA1): HMAC failed");
543
- }
544
- return ret;
598
+ if (HMAC(EVP_sha1(),
599
+ key.data(),
600
+ key_size,
601
+ reinterpret_cast<const std::uint8_t*>(data.data()),
602
+ data.size(),
603
+ reinterpret_cast<std::uint8_t*>(ret.data()),
604
+ nullptr) == nullptr) {
605
+ throw std::runtime_error("couchbase::core::crypto::HMAC(SHA1): HMAC failed");
606
+ }
607
+ return ret;
545
608
  }
546
609
 
547
610
  static std::string
548
611
  HMAC_SHA256(std::string_view key, std::string_view data)
549
612
  {
550
- std::string ret;
551
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
613
+ std::string ret;
614
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
552
615
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
553
- auto key_size = key.size();
616
+ auto key_size = key.size();
554
617
  #else
555
- auto key_size = static_cast<int>(key.size());
618
+ auto key_size = static_cast<int>(key.size());
556
619
  #endif
557
- if (HMAC(EVP_sha256(),
558
- key.data(),
559
- key_size,
560
- reinterpret_cast<const std::uint8_t*>(data.data()),
561
- data.size(),
562
- reinterpret_cast<std::uint8_t*>(ret.data()),
563
- nullptr) == nullptr) {
564
- throw std::runtime_error("couchbase::core::crypto::HMAC(SHA256): HMAC failed");
565
- }
566
- return ret;
620
+ if (HMAC(EVP_sha256(),
621
+ key.data(),
622
+ key_size,
623
+ reinterpret_cast<const std::uint8_t*>(data.data()),
624
+ data.size(),
625
+ reinterpret_cast<std::uint8_t*>(ret.data()),
626
+ nullptr) == nullptr) {
627
+ throw std::runtime_error("couchbase::core::crypto::HMAC(SHA256): HMAC failed");
628
+ }
629
+ return ret;
567
630
  }
568
631
 
569
632
  static std::string
570
633
  HMAC_SHA512(std::string_view key, std::string_view data)
571
634
  {
572
- std::string ret;
573
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
635
+ std::string ret;
636
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
574
637
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
575
- auto key_size = key.size();
638
+ auto key_size = key.size();
576
639
  #else
577
- auto key_size = static_cast<int>(key.size());
640
+ auto key_size = static_cast<int>(key.size());
578
641
  #endif
579
- if (HMAC(EVP_sha512(),
580
- key.data(),
581
- key_size,
582
- reinterpret_cast<const std::uint8_t*>(data.data()),
583
- data.size(),
584
- reinterpret_cast<std::uint8_t*>(ret.data()),
585
- nullptr) == nullptr) {
586
- throw std::runtime_error("couchbase::core::crypto::HMAC(SHA512): HMAC failed");
587
- }
588
- return ret;
642
+ if (HMAC(EVP_sha512(),
643
+ key.data(),
644
+ key_size,
645
+ reinterpret_cast<const std::uint8_t*>(data.data()),
646
+ data.size(),
647
+ reinterpret_cast<std::uint8_t*>(ret.data()),
648
+ nullptr) == nullptr) {
649
+ throw std::runtime_error("couchbase::core::crypto::HMAC(SHA512): HMAC failed");
650
+ }
651
+ return ret;
589
652
  }
590
653
 
591
654
  static std::string
592
655
  PBKDF2_HMAC_SHA1(const std::string& pass, std::string_view salt, unsigned int iterationCount)
593
656
  {
594
- std::string ret;
595
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
657
+ std::string ret;
658
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
596
659
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
597
- auto pw_size = pass.size();
598
- auto salt_size = salt.size();
599
- auto iteration_count = iterationCount;
660
+ auto pw_size = pass.size();
661
+ auto salt_size = salt.size();
662
+ auto iteration_count = iterationCount;
600
663
  #else
601
- auto pw_size = int(pass.size());
602
- auto salt_size = int(salt.size());
603
- auto iteration_count = int(iterationCount);
664
+ auto pw_size = int(pass.size());
665
+ auto salt_size = int(salt.size());
666
+ auto iteration_count = int(iterationCount);
604
667
  #endif
605
- auto err = PKCS5_PBKDF2_HMAC(pass.data(),
606
- pw_size,
607
- reinterpret_cast<const std::uint8_t*>(salt.data()),
608
- salt_size,
609
- iteration_count,
610
- EVP_sha1(),
611
- couchbase::core::crypto::SHA1_DIGEST_SIZE,
612
- reinterpret_cast<std::uint8_t*>(ret.data()));
613
-
614
- if (err != 1) {
615
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA1): PKCS5_PBKDF2_HMAC_SHA1 "
616
- "failed: " +
617
- std::to_string(err));
618
- }
619
-
620
- return ret;
668
+ auto err = PKCS5_PBKDF2_HMAC(pass.data(),
669
+ pw_size,
670
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
671
+ salt_size,
672
+ iteration_count,
673
+ EVP_sha1(),
674
+ couchbase::core::crypto::SHA1_DIGEST_SIZE,
675
+ reinterpret_cast<std::uint8_t*>(ret.data()));
676
+
677
+ if (err != 1) {
678
+ throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA1): PKCS5_PBKDF2_HMAC_SHA1 "
679
+ "failed: " +
680
+ std::to_string(err));
681
+ }
682
+
683
+ return ret;
621
684
  }
622
685
 
623
686
  static std::string
624
687
  PBKDF2_HMAC_SHA256(const std::string& pass, std::string_view salt, unsigned int iterationCount)
625
688
  {
626
- std::string ret;
627
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
689
+ std::string ret;
690
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
628
691
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
629
- auto pw_size = pass.size();
630
- auto salt_size = salt.size();
631
- auto iteration_count = iterationCount;
692
+ auto pw_size = pass.size();
693
+ auto salt_size = salt.size();
694
+ auto iteration_count = iterationCount;
632
695
  #else
633
- auto pw_size = int(pass.size());
634
- auto salt_size = int(salt.size());
635
- auto iteration_count = int(iterationCount);
696
+ auto pw_size = int(pass.size());
697
+ auto salt_size = int(salt.size());
698
+ auto iteration_count = int(iterationCount);
636
699
  #endif
637
- auto err = PKCS5_PBKDF2_HMAC(pass.data(),
638
- pw_size,
639
- reinterpret_cast<const std::uint8_t*>(salt.data()),
640
- salt_size,
641
- iteration_count,
642
- EVP_sha256(),
643
- couchbase::core::crypto::SHA256_DIGEST_SIZE,
644
- reinterpret_cast<std::uint8_t*>(ret.data()));
645
- if (err != 1) {
646
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA256): PKCS5_PBKDF2_HMAC failed" + std::to_string(err));
647
- }
648
-
649
- return ret;
700
+ auto err = PKCS5_PBKDF2_HMAC(pass.data(),
701
+ pw_size,
702
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
703
+ salt_size,
704
+ iteration_count,
705
+ EVP_sha256(),
706
+ couchbase::core::crypto::SHA256_DIGEST_SIZE,
707
+ reinterpret_cast<std::uint8_t*>(ret.data()));
708
+ if (err != 1) {
709
+ throw std::runtime_error(
710
+ "couchbase::core::crypto::PBKDF2_HMAC(SHA256): PKCS5_PBKDF2_HMAC failed" +
711
+ std::to_string(err));
712
+ }
713
+
714
+ return ret;
650
715
  }
651
716
 
652
717
  static std::string
653
718
  PBKDF2_HMAC_SHA512(const std::string& pass, std::string_view salt, unsigned int iterationCount)
654
719
  {
655
- std::string ret;
656
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
720
+ std::string ret;
721
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
657
722
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
658
- auto pw_size = pass.size();
659
- auto salt_size = salt.size();
660
- auto iteration_count = iterationCount;
723
+ auto pw_size = pass.size();
724
+ auto salt_size = salt.size();
725
+ auto iteration_count = iterationCount;
661
726
  #else
662
- auto pw_size = int(pass.size());
663
- auto salt_size = int(salt.size());
664
- auto iteration_count = int(iterationCount);
727
+ auto pw_size = int(pass.size());
728
+ auto salt_size = int(salt.size());
729
+ auto iteration_count = int(iterationCount);
665
730
  #endif
666
- auto err = PKCS5_PBKDF2_HMAC(pass.data(),
667
- pw_size,
668
- reinterpret_cast<const std::uint8_t*>(salt.data()),
669
- salt_size,
670
- iteration_count,
671
- EVP_sha512(),
672
- couchbase::core::crypto::SHA512_DIGEST_SIZE,
673
- reinterpret_cast<std::uint8_t*>(ret.data()));
674
- if (err != 1) {
675
- throw std::runtime_error("couchbase::core::crypto::PBKDF2_HMAC(SHA512): PKCS5_PBKDF2_HMAC failed" + std::to_string(err));
676
- }
677
-
678
- return ret;
731
+ auto err = PKCS5_PBKDF2_HMAC(pass.data(),
732
+ pw_size,
733
+ reinterpret_cast<const std::uint8_t*>(salt.data()),
734
+ salt_size,
735
+ iteration_count,
736
+ EVP_sha512(),
737
+ couchbase::core::crypto::SHA512_DIGEST_SIZE,
738
+ reinterpret_cast<std::uint8_t*>(ret.data()));
739
+ if (err != 1) {
740
+ throw std::runtime_error(
741
+ "couchbase::core::crypto::PBKDF2_HMAC(SHA512): PKCS5_PBKDF2_HMAC failed" +
742
+ std::to_string(err));
743
+ }
744
+
745
+ return ret;
679
746
  }
680
747
 
681
748
  static std::string
682
749
  digest_sha1(std::string_view data)
683
750
  {
684
- std::string ret;
685
- ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
686
- SHA1(reinterpret_cast<const std::uint8_t*>(data.data()), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
687
- return ret;
751
+ std::string ret;
752
+ ret.resize(couchbase::core::crypto::SHA1_DIGEST_SIZE);
753
+ SHA1(reinterpret_cast<const std::uint8_t*>(data.data()),
754
+ data.size(),
755
+ reinterpret_cast<std::uint8_t*>(ret.data()));
756
+ return ret;
688
757
  }
689
758
 
690
759
  static std::string
691
760
  digest_sha256(std::string_view data)
692
761
  {
693
- std::string ret;
694
- ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
695
- SHA256(reinterpret_cast<const std::uint8_t*>(data.data()), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
696
- return ret;
762
+ std::string ret;
763
+ ret.resize(couchbase::core::crypto::SHA256_DIGEST_SIZE);
764
+ SHA256(reinterpret_cast<const std::uint8_t*>(data.data()),
765
+ data.size(),
766
+ reinterpret_cast<std::uint8_t*>(ret.data()));
767
+ return ret;
697
768
  }
698
769
 
699
770
  static std::string
700
771
  digest_sha512(std::string_view data)
701
772
  {
702
- std::string ret;
703
- ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
704
- SHA512(reinterpret_cast<const std::uint8_t*>(data.data()), data.size(), reinterpret_cast<std::uint8_t*>(ret.data()));
705
- return ret;
773
+ std::string ret;
774
+ ret.resize(couchbase::core::crypto::SHA512_DIGEST_SIZE);
775
+ SHA512(reinterpret_cast<const std::uint8_t*>(data.data()),
776
+ data.size(),
777
+ reinterpret_cast<std::uint8_t*>(ret.data()));
778
+ return ret;
706
779
  }
707
780
 
708
781
  struct EVP_CIPHER_CTX_Deleter {
709
- void operator()(EVP_CIPHER_CTX* ctx)
710
- {
711
- if (ctx != nullptr) {
712
- EVP_CIPHER_CTX_free(ctx);
713
- }
782
+ void operator()(EVP_CIPHER_CTX* ctx)
783
+ {
784
+ if (ctx != nullptr) {
785
+ EVP_CIPHER_CTX_free(ctx);
714
786
  }
787
+ }
715
788
  };
716
789
 
717
790
  using unique_EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_Deleter>;
@@ -723,106 +796,121 @@ using unique_EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, EVP_CIPHER_CTX
723
796
  static const EVP_CIPHER*
724
797
  getCipher(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv)
725
798
  {
726
- const EVP_CIPHER* cip = nullptr;
727
-
728
- switch (cipher) {
729
- case couchbase::core::crypto::Cipher::AES_256_cbc:
730
- cip = EVP_aes_256_cbc();
731
- break;
732
- }
733
-
734
- if (cip == nullptr) {
735
- throw std::invalid_argument("couchbase::core::crypto::getCipher: Unknown Cipher " + std::to_string(int(cipher)));
736
- }
799
+ const EVP_CIPHER* cip = nullptr;
800
+
801
+ switch (cipher) {
802
+ case couchbase::core::crypto::Cipher::AES_256_cbc:
803
+ cip = EVP_aes_256_cbc();
804
+ break;
805
+ }
806
+
807
+ if (cip == nullptr) {
808
+ throw std::invalid_argument("couchbase::core::crypto::getCipher: Unknown Cipher " +
809
+ std::to_string(int(cipher)));
810
+ }
737
811
  #ifdef COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL
738
- auto key_size = key.size();
739
- auto iv_size = iv.size();
812
+ auto key_size = key.size();
813
+ auto iv_size = iv.size();
740
814
  #else
741
- // NOTE that OpenSSL 3 changed EVP_CIPHER_key_length() -> EVP_CIPHER_get_key_length()
742
- auto key_size = int(key.size());
743
- auto iv_size = int(iv.size());
815
+ // NOTE that OpenSSL 3 changed EVP_CIPHER_key_length() -> EVP_CIPHER_get_key_length()
816
+ auto key_size = int(key.size());
817
+ auto iv_size = int(iv.size());
744
818
  #endif
745
- if (key_size != EVP_CIPHER_key_length(cip)) {
746
- throw std::invalid_argument("couchbase::core::crypto::getCipher: Cipher requires a key "
747
- "length of " +
748
- std::to_string(EVP_CIPHER_key_length(cip)) + " provided key with length " + std::to_string(key.size()));
749
- }
750
-
751
- if (iv_size != EVP_CIPHER_iv_length(cip)) {
752
- throw std::invalid_argument("couchbase::core::crypto::getCipher: Cipher requires a iv "
753
- "length of " +
754
- std::to_string(EVP_CIPHER_iv_length(cip)) + " provided iv with length " + std::to_string(iv.size()));
755
- }
756
-
757
- return cip;
819
+ if (key_size != EVP_CIPHER_key_length(cip)) {
820
+ throw std::invalid_argument("couchbase::core::crypto::getCipher: Cipher requires a key "
821
+ "length of " +
822
+ std::to_string(EVP_CIPHER_key_length(cip)) +
823
+ " provided key with length " + std::to_string(key.size()));
824
+ }
825
+
826
+ if (iv_size != EVP_CIPHER_iv_length(cip)) {
827
+ throw std::invalid_argument("couchbase::core::crypto::getCipher: Cipher requires a iv "
828
+ "length of " +
829
+ std::to_string(EVP_CIPHER_iv_length(cip)) +
830
+ " provided iv with length " + std::to_string(iv.size()));
831
+ }
832
+
833
+ return cip;
758
834
  }
759
835
 
760
836
  std::string
761
- encrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
837
+ encrypt(const couchbase::core::crypto::Cipher cipher,
838
+ std::string_view key,
839
+ std::string_view iv,
840
+ std::string_view data)
762
841
  {
763
- unique_EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new());
764
-
765
- auto* cip = getCipher(cipher, key, iv);
766
- if (EVP_EncryptInit_ex(
767
- ctx.get(), cip, nullptr, reinterpret_cast<const std::uint8_t*>(key.data()), reinterpret_cast<const std::uint8_t*>(iv.data())) !=
768
- 1) {
769
- throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptInit_ex failed");
770
- }
771
-
772
- std::string ret;
773
- ret.resize(data.size() + static_cast<std::string_view::size_type>(EVP_CIPHER_block_size(cip)));
774
- int len1 = int(ret.size());
775
-
776
- if (EVP_EncryptUpdate(ctx.get(),
777
- reinterpret_cast<std::uint8_t*>(ret.data()),
778
- &len1,
779
- reinterpret_cast<const std::uint8_t*>(data.data()),
780
- int(data.size())) != 1) {
781
- throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptUpdate failed");
782
- }
783
-
784
- int len2 = int(ret.size()) - len1;
785
- if (EVP_EncryptFinal_ex(ctx.get(), reinterpret_cast<std::uint8_t*>(ret.data()) + len1, &len2) != 1) {
786
- throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptFinal_ex failed");
787
- }
788
-
789
- // Resize the destination to the sum of the two length fields
790
- ret.resize(size_t(len1) + size_t(len2));
791
- return ret;
842
+ unique_EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new());
843
+
844
+ auto* cip = getCipher(cipher, key, iv);
845
+ if (EVP_EncryptInit_ex(ctx.get(),
846
+ cip,
847
+ nullptr,
848
+ reinterpret_cast<const std::uint8_t*>(key.data()),
849
+ reinterpret_cast<const std::uint8_t*>(iv.data())) != 1) {
850
+ throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptInit_ex failed");
851
+ }
852
+
853
+ std::string ret;
854
+ ret.resize(data.size() + static_cast<std::string_view::size_type>(EVP_CIPHER_block_size(cip)));
855
+ int len1 = int(ret.size());
856
+
857
+ if (EVP_EncryptUpdate(ctx.get(),
858
+ reinterpret_cast<std::uint8_t*>(ret.data()),
859
+ &len1,
860
+ reinterpret_cast<const std::uint8_t*>(data.data()),
861
+ int(data.size())) != 1) {
862
+ throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptUpdate failed");
863
+ }
864
+
865
+ int len2 = int(ret.size()) - len1;
866
+ if (EVP_EncryptFinal_ex(ctx.get(), reinterpret_cast<std::uint8_t*>(ret.data()) + len1, &len2) !=
867
+ 1) {
868
+ throw std::runtime_error("couchbase::core::crypto::encrypt: EVP_EncryptFinal_ex failed");
869
+ }
870
+
871
+ // Resize the destination to the sum of the two length fields
872
+ ret.resize(size_t(len1) + size_t(len2));
873
+ return ret;
792
874
  }
793
875
 
794
876
  std::string
795
- decrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
877
+ decrypt(const couchbase::core::crypto::Cipher cipher,
878
+ std::string_view key,
879
+ std::string_view iv,
880
+ std::string_view data)
796
881
  {
797
- unique_EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new());
798
- auto* cip = getCipher(cipher, key, iv);
799
-
800
- if (EVP_DecryptInit_ex(
801
- ctx.get(), cip, nullptr, reinterpret_cast<const std::uint8_t*>(key.data()), reinterpret_cast<const std::uint8_t*>(iv.data())) !=
802
- 1) {
803
- throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptInit_ex failed");
804
- }
805
-
806
- std::string ret;
807
- ret.resize(data.size());
808
- int len1 = int(ret.size());
809
-
810
- if (EVP_DecryptUpdate(ctx.get(),
811
- reinterpret_cast<std::uint8_t*>(ret.data()),
812
- &len1,
813
- reinterpret_cast<const std::uint8_t*>(data.data()),
814
- int(data.size())) != 1) {
815
- throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptUpdate failed");
816
- }
817
-
818
- int len2 = int(data.size()) - len1;
819
- if (EVP_DecryptFinal_ex(ctx.get(), reinterpret_cast<std::uint8_t*>(ret.data()) + len1, &len2) != 1) {
820
- throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptFinal_ex failed");
821
- }
822
-
823
- // Resize the destination to the sum of the two length fields
824
- ret.resize(size_t(len1) + size_t(len2));
825
- return ret;
882
+ unique_EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new());
883
+ auto* cip = getCipher(cipher, key, iv);
884
+
885
+ if (EVP_DecryptInit_ex(ctx.get(),
886
+ cip,
887
+ nullptr,
888
+ reinterpret_cast<const std::uint8_t*>(key.data()),
889
+ reinterpret_cast<const std::uint8_t*>(iv.data())) != 1) {
890
+ throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptInit_ex failed");
891
+ }
892
+
893
+ std::string ret;
894
+ ret.resize(data.size());
895
+ int len1 = int(ret.size());
896
+
897
+ if (EVP_DecryptUpdate(ctx.get(),
898
+ reinterpret_cast<std::uint8_t*>(ret.data()),
899
+ &len1,
900
+ reinterpret_cast<const std::uint8_t*>(data.data()),
901
+ int(data.size())) != 1) {
902
+ throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptUpdate failed");
903
+ }
904
+
905
+ int len2 = int(data.size()) - len1;
906
+ if (EVP_DecryptFinal_ex(ctx.get(), reinterpret_cast<std::uint8_t*>(ret.data()) + len1, &len2) !=
907
+ 1) {
908
+ throw std::runtime_error("couchbase::core::crypto::decrypt: EVP_DecryptFinal_ex failed");
909
+ }
910
+
911
+ // Resize the destination to the sum of the two length fields
912
+ ret.resize(size_t(len1) + size_t(len2));
913
+ return ret;
826
914
  }
827
915
 
828
916
  #endif
@@ -830,120 +918,137 @@ decrypt(const couchbase::core::crypto::Cipher cipher, std::string_view key, std:
830
918
  } // namespace internal
831
919
 
832
920
  std::string
833
- couchbase::core::crypto::CBC_HMAC(const Algorithm algorithm, std::string_view key, std::string_view data)
834
- {
835
- switch (algorithm) {
836
- case couchbase::core::crypto::Algorithm::ALG_SHA1:
837
- return internal::HMAC_SHA1(key, data);
838
- case Algorithm::ALG_SHA256:
839
- return internal::HMAC_SHA256(key, data);
840
- case Algorithm::ALG_SHA512:
841
- return internal::HMAC_SHA512(key, data);
842
- }
843
-
844
- throw std::invalid_argument("couchbase::core::crypto::HMAC: Unknown Algorithm: " + std::to_string(int(algorithm)));
921
+ couchbase::core::crypto::CBC_HMAC(const Algorithm algorithm,
922
+ std::string_view key,
923
+ std::string_view data)
924
+ {
925
+ switch (algorithm) {
926
+ case couchbase::core::crypto::Algorithm::ALG_SHA1:
927
+ return internal::HMAC_SHA1(key, data);
928
+ case Algorithm::ALG_SHA256:
929
+ return internal::HMAC_SHA256(key, data);
930
+ case Algorithm::ALG_SHA512:
931
+ return internal::HMAC_SHA512(key, data);
932
+ }
933
+
934
+ throw std::invalid_argument("couchbase::core::crypto::HMAC: Unknown Algorithm: " +
935
+ std::to_string(int(algorithm)));
845
936
  }
846
937
 
847
938
  std::string
848
- couchbase::core::crypto::PBKDF2_HMAC(const Algorithm algorithm, const std::string& pass, std::string_view salt, unsigned int iterationCount)
849
- {
850
- switch (algorithm) {
851
- case Algorithm::ALG_SHA1:
852
- return internal::PBKDF2_HMAC_SHA1(pass, salt, iterationCount);
853
- case Algorithm::ALG_SHA256:
854
- return internal::PBKDF2_HMAC_SHA256(pass, salt, iterationCount);
855
- case Algorithm::ALG_SHA512:
856
- return internal::PBKDF2_HMAC_SHA512(pass, salt, iterationCount);
857
- }
858
-
859
- throw std::invalid_argument("couchbase::core::crypto::PBKDF2_HMAC: Unknown Algorithm: " + std::to_string(int(algorithm)));
939
+ couchbase::core::crypto::PBKDF2_HMAC(const Algorithm algorithm,
940
+ const std::string& pass,
941
+ std::string_view salt,
942
+ unsigned int iterationCount)
943
+ {
944
+ switch (algorithm) {
945
+ case Algorithm::ALG_SHA1:
946
+ return internal::PBKDF2_HMAC_SHA1(pass, salt, iterationCount);
947
+ case Algorithm::ALG_SHA256:
948
+ return internal::PBKDF2_HMAC_SHA256(pass, salt, iterationCount);
949
+ case Algorithm::ALG_SHA512:
950
+ return internal::PBKDF2_HMAC_SHA512(pass, salt, iterationCount);
951
+ }
952
+
953
+ throw std::invalid_argument("couchbase::core::crypto::PBKDF2_HMAC: Unknown Algorithm: " +
954
+ std::to_string(int(algorithm)));
860
955
  }
861
956
 
862
957
  static inline void
863
958
  verifyLegalAlgorithm(const couchbase::core::crypto::Algorithm al)
864
959
  {
865
- switch (al) {
866
- case couchbase::core::crypto::Algorithm::ALG_SHA1:
867
- case couchbase::core::crypto::Algorithm::ALG_SHA256:
868
- case couchbase::core::crypto::Algorithm::ALG_SHA512:
869
- return;
870
- }
871
- throw std::invalid_argument("verifyLegalAlgorithm: Unknown Algorithm: " + std::to_string(int(al)));
960
+ switch (al) {
961
+ case couchbase::core::crypto::Algorithm::ALG_SHA1:
962
+ case couchbase::core::crypto::Algorithm::ALG_SHA256:
963
+ case couchbase::core::crypto::Algorithm::ALG_SHA512:
964
+ return;
965
+ }
966
+ throw std::invalid_argument("verifyLegalAlgorithm: Unknown Algorithm: " +
967
+ std::to_string(int(al)));
872
968
  }
873
969
 
874
970
  bool
875
971
  couchbase::core::crypto::isSupported(const Algorithm algorithm)
876
972
  {
877
- verifyLegalAlgorithm(algorithm);
973
+ verifyLegalAlgorithm(algorithm);
878
974
 
879
- return true;
975
+ return true;
880
976
  }
881
977
 
882
978
  std::string
883
979
  couchbase::core::crypto::digest(const Algorithm algorithm, std::string_view data)
884
980
  {
885
- switch (algorithm) {
886
- case Algorithm::ALG_SHA1:
887
- return internal::digest_sha1(data);
888
- case Algorithm::ALG_SHA256:
889
- return internal::digest_sha256(data);
890
- case Algorithm::ALG_SHA512:
891
- return internal::digest_sha512(data);
892
- }
893
-
894
- throw std::invalid_argument("couchbase::core::crypto::digest: Unknown Algorithm" + std::to_string(int(algorithm)));
981
+ switch (algorithm) {
982
+ case Algorithm::ALG_SHA1:
983
+ return internal::digest_sha1(data);
984
+ case Algorithm::ALG_SHA256:
985
+ return internal::digest_sha256(data);
986
+ case Algorithm::ALG_SHA512:
987
+ return internal::digest_sha512(data);
988
+ }
989
+
990
+ throw std::invalid_argument("couchbase::core::crypto::digest: Unknown Algorithm" +
991
+ std::to_string(int(algorithm)));
895
992
  }
896
993
 
897
994
  std::string
898
- couchbase::core::crypto::encrypt(const Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
995
+ couchbase::core::crypto::encrypt(const Cipher cipher,
996
+ std::string_view key,
997
+ std::string_view iv,
998
+ std::string_view data)
899
999
  {
900
- // We only support a single encryption scheme right now.
901
- // Verify the input parameters (no need of calling the internal library
902
- // functions in order to fetch these details)
903
- if (cipher != Cipher::AES_256_cbc) {
904
- throw std::invalid_argument("couchbase::core::crypto::encrypt(): Unsupported cipher");
905
- }
906
-
907
- if (key.size() != 32) {
908
- throw std::invalid_argument("couchbase::core::crypto::encrypt(): Invalid key size: " + std::to_string(key.size()) +
909
- " (expected 32)");
910
- }
911
-
912
- if (iv.size() != 16) {
913
- throw std::invalid_argument("couchbase::core::crypto::encrypt(): Invalid iv size: " + std::to_string(iv.size()) + " (expected 16)");
914
- }
915
-
916
- return internal::encrypt(cipher, key, iv, data);
1000
+ // We only support a single encryption scheme right now.
1001
+ // Verify the input parameters (no need of calling the internal library
1002
+ // functions in order to fetch these details)
1003
+ if (cipher != Cipher::AES_256_cbc) {
1004
+ throw std::invalid_argument("couchbase::core::crypto::encrypt(): Unsupported cipher");
1005
+ }
1006
+
1007
+ if (key.size() != 32) {
1008
+ throw std::invalid_argument("couchbase::core::crypto::encrypt(): Invalid key size: " +
1009
+ std::to_string(key.size()) + " (expected 32)");
1010
+ }
1011
+
1012
+ if (iv.size() != 16) {
1013
+ throw std::invalid_argument("couchbase::core::crypto::encrypt(): Invalid iv size: " +
1014
+ std::to_string(iv.size()) + " (expected 16)");
1015
+ }
1016
+
1017
+ return internal::encrypt(cipher, key, iv, data);
917
1018
  }
918
1019
 
919
1020
  std::string
920
- couchbase::core::crypto::decrypt(const Cipher cipher, std::string_view key, std::string_view iv, std::string_view data)
1021
+ couchbase::core::crypto::decrypt(const Cipher cipher,
1022
+ std::string_view key,
1023
+ std::string_view iv,
1024
+ std::string_view data)
921
1025
  {
922
- // We only support a single decryption scheme right now.
923
- // Verify the input parameters (no need of calling the internal library
924
- // functions in order to fetch these details)
925
- if (cipher != Cipher::AES_256_cbc) {
926
- throw std::invalid_argument("couchbase::core::crypto::decrypt(): Unsupported cipher");
927
- }
928
-
929
- if (key.size() != 32) {
930
- throw std::invalid_argument("couchbase::core::crypto::decrypt(): Invalid key size: " + std::to_string(key.size()) +
931
- " (expected 32)");
932
- }
933
-
934
- if (iv.size() != 16) {
935
- throw std::invalid_argument("couchbase::core::crypto::decrypt(): Invalid iv size: " + std::to_string(iv.size()) + " (expected 16)");
936
- }
937
-
938
- return internal::decrypt(cipher, key, iv, data);
1026
+ // We only support a single decryption scheme right now.
1027
+ // Verify the input parameters (no need of calling the internal library
1028
+ // functions in order to fetch these details)
1029
+ if (cipher != Cipher::AES_256_cbc) {
1030
+ throw std::invalid_argument("couchbase::core::crypto::decrypt(): Unsupported cipher");
1031
+ }
1032
+
1033
+ if (key.size() != 32) {
1034
+ throw std::invalid_argument("couchbase::core::crypto::decrypt(): Invalid key size: " +
1035
+ std::to_string(key.size()) + " (expected 32)");
1036
+ }
1037
+
1038
+ if (iv.size() != 16) {
1039
+ throw std::invalid_argument("couchbase::core::crypto::decrypt(): Invalid iv size: " +
1040
+ std::to_string(iv.size()) + " (expected 16)");
1041
+ }
1042
+
1043
+ return internal::decrypt(cipher, key, iv, data);
939
1044
  }
940
1045
 
941
1046
  couchbase::core::crypto::Cipher
942
1047
  couchbase::core::crypto::to_cipher(const std::string& str)
943
1048
  {
944
- if (str == "AES_256_cbc") {
945
- return Cipher::AES_256_cbc;
946
- }
1049
+ if (str == "AES_256_cbc") {
1050
+ return Cipher::AES_256_cbc;
1051
+ }
947
1052
 
948
- throw std::invalid_argument("to_cipher: Unknown cipher: " + str);
1053
+ throw std::invalid_argument("to_cipher: Unknown cipher: " + str);
949
1054
  }