grpc 1.26.0 → 1.27.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +1654 -1519
- data/etc/roots.pem +44 -0
- data/include/grpc/grpc_security.h +37 -15
- data/include/grpc/grpc_security_constants.h +27 -0
- data/include/grpc/impl/codegen/grpc_types.h +14 -0
- data/include/grpc/impl/codegen/port_platform.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
- data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +3 -10
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
- data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
- data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
- data/src/core/lib/channel/channelz.h +11 -1
- data/src/core/lib/gpr/time_precise.cc +1 -1
- data/src/core/lib/gprpp/optional.h +26 -0
- data/src/core/lib/gprpp/string_view.h +14 -10
- data/src/core/lib/iomgr/executor.cc +1 -1
- data/src/core/lib/iomgr/fork_posix.cc +4 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
- data/src/core/lib/iomgr/tcp_custom.h +3 -0
- data/src/core/lib/iomgr/tcp_posix.cc +607 -56
- data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
- data/src/core/lib/json/json.h +11 -1
- data/src/core/lib/json/json_reader.cc +206 -28
- data/src/core/lib/json/json_writer.cc +111 -24
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
- data/src/core/lib/security/credentials/credentials.h +10 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
- data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
- data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
- data/src/core/lib/surface/completion_queue.cc +22 -1
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +7 -3
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl_transport_security.cc +144 -8
- data/src/core/tsi/ssl_transport_security.h +15 -1
- data/src/core/tsi/transport_security.cc +13 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -2
- data/src/core/tsi/transport_security_grpc.h +2 -2
- data/src/core/tsi/transport_security_interface.h +12 -0
- data/src/ruby/bin/math_pb.rb +5 -5
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
- data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
- data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
- data/third_party/abseil-cpp/absl/base/casts.h +184 -0
- data/third_party/abseil-cpp/absl/base/config.h +622 -0
- data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
- data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
- data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
- data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
- data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
- data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
- data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
- data/third_party/abseil-cpp/absl/base/macros.h +220 -0
- data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
- data/third_party/abseil-cpp/absl/base/options.h +214 -0
- data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
- data/third_party/abseil-cpp/absl/base/port.h +26 -0
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
- data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
- data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
- data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
- data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
- data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
- data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
- data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
- data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
- data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
- data/third_party/abseil-cpp/absl/strings/match.h +90 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
- data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
- data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
- data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
- data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
- data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
- data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
- data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
- data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
- data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
- data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
- data/third_party/abseil-cpp/absl/types/optional.h +776 -0
- data/third_party/abseil-cpp/absl/types/span.h +713 -0
- data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
- data/third_party/upb/upb/decode.c +4 -0
- data/third_party/upb/upb/port.c +0 -1
- data/third_party/upb/upb/port_def.inc +1 -3
- data/third_party/upb/upb/table.c +2 -1
- metadata +147 -43
- data/src/core/lib/json/json_common.h +0 -34
- data/src/core/lib/json/json_reader.h +0 -146
- data/src/core/lib/json/json_string.cc +0 -367
- data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,99 @@
|
|
1
|
+
// Copyright 2018 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#ifndef ABSL_STRINGS_INTERNAL_CHARCONV_PARSE_H_
|
16
|
+
#define ABSL_STRINGS_INTERNAL_CHARCONV_PARSE_H_
|
17
|
+
|
18
|
+
#include <cstdint>
|
19
|
+
|
20
|
+
#include "absl/base/config.h"
|
21
|
+
#include "absl/strings/charconv.h"
|
22
|
+
|
23
|
+
namespace absl {
|
24
|
+
ABSL_NAMESPACE_BEGIN
|
25
|
+
namespace strings_internal {
|
26
|
+
|
27
|
+
// Enum indicating whether a parsed float is a number or special value.
|
28
|
+
enum class FloatType { kNumber, kInfinity, kNan };
|
29
|
+
|
30
|
+
// The decomposed parts of a parsed `float` or `double`.
|
31
|
+
struct ParsedFloat {
|
32
|
+
// Representation of the parsed mantissa, with the decimal point adjusted to
|
33
|
+
// make it an integer.
|
34
|
+
//
|
35
|
+
// During decimal scanning, this contains 19 significant digits worth of
|
36
|
+
// mantissa value. If digits beyond this point are found, they
|
37
|
+
// are truncated, and if any of these dropped digits are nonzero, then
|
38
|
+
// `mantissa` is inexact, and the full mantissa is stored in [subrange_begin,
|
39
|
+
// subrange_end).
|
40
|
+
//
|
41
|
+
// During hexadecimal scanning, this contains 15 significant hex digits worth
|
42
|
+
// of mantissa value. Digits beyond this point are sticky -- they are
|
43
|
+
// truncated, but if any dropped digits are nonzero, the low bit of mantissa
|
44
|
+
// will be set. (This allows for precise rounding, and avoids the need
|
45
|
+
// to store the full mantissa in [subrange_begin, subrange_end).)
|
46
|
+
uint64_t mantissa = 0;
|
47
|
+
|
48
|
+
// Floating point expontent. This reflects any decimal point adjustments and
|
49
|
+
// any truncated digits from the mantissa. The absolute value of the parsed
|
50
|
+
// number is represented by mantissa * (base ** exponent), where base==10 for
|
51
|
+
// decimal floats, and base==2 for hexadecimal floats.
|
52
|
+
int exponent = 0;
|
53
|
+
|
54
|
+
// The literal exponent value scanned from the input, or 0 if none was
|
55
|
+
// present. This does not reflect any adjustments applied to mantissa.
|
56
|
+
int literal_exponent = 0;
|
57
|
+
|
58
|
+
// The type of number scanned.
|
59
|
+
FloatType type = FloatType::kNumber;
|
60
|
+
|
61
|
+
// When non-null, [subrange_begin, subrange_end) marks a range of characters
|
62
|
+
// that require further processing. The meaning is dependent on float type.
|
63
|
+
// If type == kNumber and this is set, this is a "wide input": the input
|
64
|
+
// mantissa contained more than 19 digits. The range contains the full
|
65
|
+
// mantissa. It plus `literal_exponent` need to be examined to find the best
|
66
|
+
// floating point match.
|
67
|
+
// If type == kNan and this is set, the range marks the contents of a
|
68
|
+
// matched parenthesized character region after the NaN.
|
69
|
+
const char* subrange_begin = nullptr;
|
70
|
+
const char* subrange_end = nullptr;
|
71
|
+
|
72
|
+
// One-past-the-end of the successfully parsed region, or nullptr if no
|
73
|
+
// matching pattern was found.
|
74
|
+
const char* end = nullptr;
|
75
|
+
};
|
76
|
+
|
77
|
+
// Read the floating point number in the provided range, and populate
|
78
|
+
// ParsedFloat accordingly.
|
79
|
+
//
|
80
|
+
// format_flags is a bitmask value specifying what patterns this API will match.
|
81
|
+
// `scientific` and `fixed` are honored per std::from_chars rules
|
82
|
+
// ([utility.from.chars], C++17): if exactly one of these bits is set, then an
|
83
|
+
// exponent is required, or dislallowed, respectively.
|
84
|
+
//
|
85
|
+
// Template parameter `base` must be either 10 or 16. For base 16, a "0x" is
|
86
|
+
// *not* consumed. The `hex` bit from format_flags is ignored by ParseFloat.
|
87
|
+
template <int base>
|
88
|
+
ParsedFloat ParseFloat(const char* begin, const char* end,
|
89
|
+
absl::chars_format format_flags);
|
90
|
+
|
91
|
+
extern template ParsedFloat ParseFloat<10>(const char* begin, const char* end,
|
92
|
+
absl::chars_format format_flags);
|
93
|
+
extern template ParsedFloat ParseFloat<16>(const char* begin, const char* end,
|
94
|
+
absl::chars_format format_flags);
|
95
|
+
|
96
|
+
} // namespace strings_internal
|
97
|
+
ABSL_NAMESPACE_END
|
98
|
+
} // namespace absl
|
99
|
+
#endif // ABSL_STRINGS_INTERNAL_CHARCONV_PARSE_H_
|
@@ -0,0 +1,180 @@
|
|
1
|
+
// Copyright 2020 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include "absl/strings/internal/escaping.h"
|
16
|
+
|
17
|
+
#include "absl/base/internal/endian.h"
|
18
|
+
#include "absl/base/internal/raw_logging.h"
|
19
|
+
|
20
|
+
namespace absl {
|
21
|
+
ABSL_NAMESPACE_BEGIN
|
22
|
+
namespace strings_internal {
|
23
|
+
|
24
|
+
const char kBase64Chars[] =
|
25
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
26
|
+
|
27
|
+
size_t CalculateBase64EscapedLenInternal(size_t input_len, bool do_padding) {
|
28
|
+
// Base64 encodes three bytes of input at a time. If the input is not
|
29
|
+
// divisible by three, we pad as appropriate.
|
30
|
+
//
|
31
|
+
// (from https://tools.ietf.org/html/rfc3548)
|
32
|
+
// Special processing is performed if fewer than 24 bits are available
|
33
|
+
// at the end of the data being encoded. A full encoding quantum is
|
34
|
+
// always completed at the end of a quantity. When fewer than 24 input
|
35
|
+
// bits are available in an input group, zero bits are added (on the
|
36
|
+
// right) to form an integral number of 6-bit groups. Padding at the
|
37
|
+
// end of the data is performed using the '=' character. Since all base
|
38
|
+
// 64 input is an integral number of octets, only the following cases
|
39
|
+
// can arise:
|
40
|
+
|
41
|
+
// Base64 encodes each three bytes of input into four bytes of output.
|
42
|
+
size_t len = (input_len / 3) * 4;
|
43
|
+
|
44
|
+
if (input_len % 3 == 0) {
|
45
|
+
// (from https://tools.ietf.org/html/rfc3548)
|
46
|
+
// (1) the final quantum of encoding input is an integral multiple of 24
|
47
|
+
// bits; here, the final unit of encoded output will be an integral
|
48
|
+
// multiple of 4 characters with no "=" padding,
|
49
|
+
} else if (input_len % 3 == 1) {
|
50
|
+
// (from https://tools.ietf.org/html/rfc3548)
|
51
|
+
// (2) the final quantum of encoding input is exactly 8 bits; here, the
|
52
|
+
// final unit of encoded output will be two characters followed by two
|
53
|
+
// "=" padding characters, or
|
54
|
+
len += 2;
|
55
|
+
if (do_padding) {
|
56
|
+
len += 2;
|
57
|
+
}
|
58
|
+
} else { // (input_len % 3 == 2)
|
59
|
+
// (from https://tools.ietf.org/html/rfc3548)
|
60
|
+
// (3) the final quantum of encoding input is exactly 16 bits; here, the
|
61
|
+
// final unit of encoded output will be three characters followed by one
|
62
|
+
// "=" padding character.
|
63
|
+
len += 3;
|
64
|
+
if (do_padding) {
|
65
|
+
len += 1;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
assert(len >= input_len); // make sure we didn't overflow
|
70
|
+
return len;
|
71
|
+
}
|
72
|
+
|
73
|
+
size_t Base64EscapeInternal(const unsigned char* src, size_t szsrc, char* dest,
|
74
|
+
size_t szdest, const char* base64,
|
75
|
+
bool do_padding) {
|
76
|
+
static const char kPad64 = '=';
|
77
|
+
|
78
|
+
if (szsrc * 4 > szdest * 3) return 0;
|
79
|
+
|
80
|
+
char* cur_dest = dest;
|
81
|
+
const unsigned char* cur_src = src;
|
82
|
+
|
83
|
+
char* const limit_dest = dest + szdest;
|
84
|
+
const unsigned char* const limit_src = src + szsrc;
|
85
|
+
|
86
|
+
// Three bytes of data encodes to four characters of cyphertext.
|
87
|
+
// So we can pump through three-byte chunks atomically.
|
88
|
+
if (szsrc >= 3) { // "limit_src - 3" is UB if szsrc < 3.
|
89
|
+
while (cur_src < limit_src - 3) { // While we have >= 32 bits.
|
90
|
+
uint32_t in = absl::big_endian::Load32(cur_src) >> 8;
|
91
|
+
|
92
|
+
cur_dest[0] = base64[in >> 18];
|
93
|
+
in &= 0x3FFFF;
|
94
|
+
cur_dest[1] = base64[in >> 12];
|
95
|
+
in &= 0xFFF;
|
96
|
+
cur_dest[2] = base64[in >> 6];
|
97
|
+
in &= 0x3F;
|
98
|
+
cur_dest[3] = base64[in];
|
99
|
+
|
100
|
+
cur_dest += 4;
|
101
|
+
cur_src += 3;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
// To save time, we didn't update szdest or szsrc in the loop. So do it now.
|
105
|
+
szdest = limit_dest - cur_dest;
|
106
|
+
szsrc = limit_src - cur_src;
|
107
|
+
|
108
|
+
/* now deal with the tail (<=3 bytes) */
|
109
|
+
switch (szsrc) {
|
110
|
+
case 0:
|
111
|
+
// Nothing left; nothing more to do.
|
112
|
+
break;
|
113
|
+
case 1: {
|
114
|
+
// One byte left: this encodes to two characters, and (optionally)
|
115
|
+
// two pad characters to round out the four-character cypherblock.
|
116
|
+
if (szdest < 2) return 0;
|
117
|
+
uint32_t in = cur_src[0];
|
118
|
+
cur_dest[0] = base64[in >> 2];
|
119
|
+
in &= 0x3;
|
120
|
+
cur_dest[1] = base64[in << 4];
|
121
|
+
cur_dest += 2;
|
122
|
+
szdest -= 2;
|
123
|
+
if (do_padding) {
|
124
|
+
if (szdest < 2) return 0;
|
125
|
+
cur_dest[0] = kPad64;
|
126
|
+
cur_dest[1] = kPad64;
|
127
|
+
cur_dest += 2;
|
128
|
+
szdest -= 2;
|
129
|
+
}
|
130
|
+
break;
|
131
|
+
}
|
132
|
+
case 2: {
|
133
|
+
// Two bytes left: this encodes to three characters, and (optionally)
|
134
|
+
// one pad character to round out the four-character cypherblock.
|
135
|
+
if (szdest < 3) return 0;
|
136
|
+
uint32_t in = absl::big_endian::Load16(cur_src);
|
137
|
+
cur_dest[0] = base64[in >> 10];
|
138
|
+
in &= 0x3FF;
|
139
|
+
cur_dest[1] = base64[in >> 4];
|
140
|
+
in &= 0x00F;
|
141
|
+
cur_dest[2] = base64[in << 2];
|
142
|
+
cur_dest += 3;
|
143
|
+
szdest -= 3;
|
144
|
+
if (do_padding) {
|
145
|
+
if (szdest < 1) return 0;
|
146
|
+
cur_dest[0] = kPad64;
|
147
|
+
cur_dest += 1;
|
148
|
+
szdest -= 1;
|
149
|
+
}
|
150
|
+
break;
|
151
|
+
}
|
152
|
+
case 3: {
|
153
|
+
// Three bytes left: same as in the big loop above. We can't do this in
|
154
|
+
// the loop because the loop above always reads 4 bytes, and the fourth
|
155
|
+
// byte is past the end of the input.
|
156
|
+
if (szdest < 4) return 0;
|
157
|
+
uint32_t in = (cur_src[0] << 16) + absl::big_endian::Load16(cur_src + 1);
|
158
|
+
cur_dest[0] = base64[in >> 18];
|
159
|
+
in &= 0x3FFFF;
|
160
|
+
cur_dest[1] = base64[in >> 12];
|
161
|
+
in &= 0xFFF;
|
162
|
+
cur_dest[2] = base64[in >> 6];
|
163
|
+
in &= 0x3F;
|
164
|
+
cur_dest[3] = base64[in];
|
165
|
+
cur_dest += 4;
|
166
|
+
szdest -= 4;
|
167
|
+
break;
|
168
|
+
}
|
169
|
+
default:
|
170
|
+
// Should not be reached: blocks of 4 bytes are handled
|
171
|
+
// in the while loop before this switch statement.
|
172
|
+
ABSL_RAW_LOG(FATAL, "Logic problem? szsrc = %zu", szsrc);
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
return (cur_dest - dest);
|
176
|
+
}
|
177
|
+
|
178
|
+
} // namespace strings_internal
|
179
|
+
ABSL_NAMESPACE_END
|
180
|
+
} // namespace absl
|
@@ -0,0 +1,58 @@
|
|
1
|
+
// Copyright 2020 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#ifndef ABSL_STRINGS_INTERNAL_ESCAPING_H_
|
16
|
+
#define ABSL_STRINGS_INTERNAL_ESCAPING_H_
|
17
|
+
|
18
|
+
#include <cassert>
|
19
|
+
|
20
|
+
#include "absl/strings/internal/resize_uninitialized.h"
|
21
|
+
|
22
|
+
namespace absl {
|
23
|
+
ABSL_NAMESPACE_BEGIN
|
24
|
+
namespace strings_internal {
|
25
|
+
|
26
|
+
ABSL_CONST_INIT extern const char kBase64Chars[];
|
27
|
+
|
28
|
+
// Calculates how long a string will be when it is base64 encoded given its
|
29
|
+
// length and whether or not the result should be padded.
|
30
|
+
size_t CalculateBase64EscapedLenInternal(size_t input_len, bool do_padding);
|
31
|
+
|
32
|
+
// Base64-encodes `src` using the alphabet provided in `base64` and writes the
|
33
|
+
// result to `dest`. If `do_padding` is true, `dest` is padded with '=' chars
|
34
|
+
// until its length is a multiple of 3. Returns the length of `dest`.
|
35
|
+
size_t Base64EscapeInternal(const unsigned char* src, size_t szsrc, char* dest,
|
36
|
+
size_t szdest, const char* base64, bool do_padding);
|
37
|
+
|
38
|
+
// Base64-encodes `src` using the alphabet provided in `base64` and writes the
|
39
|
+
// result to `dest`. If `do_padding` is true, `dest` is padded with '=' chars
|
40
|
+
// until its length is a multiple of 3.
|
41
|
+
template <typename String>
|
42
|
+
void Base64EscapeInternal(const unsigned char* src, size_t szsrc, String* dest,
|
43
|
+
bool do_padding, const char* base64_chars) {
|
44
|
+
const size_t calc_escaped_size =
|
45
|
+
CalculateBase64EscapedLenInternal(szsrc, do_padding);
|
46
|
+
STLStringResizeUninitialized(dest, calc_escaped_size);
|
47
|
+
|
48
|
+
const size_t escaped_len = Base64EscapeInternal(
|
49
|
+
src, szsrc, &(*dest)[0], dest->size(), base64_chars, do_padding);
|
50
|
+
assert(calc_escaped_size == escaped_len);
|
51
|
+
dest->erase(escaped_len);
|
52
|
+
}
|
53
|
+
|
54
|
+
} // namespace strings_internal
|
55
|
+
ABSL_NAMESPACE_END
|
56
|
+
} // namespace absl
|
57
|
+
|
58
|
+
#endif // ABSL_STRINGS_INTERNAL_ESCAPING_H_
|
@@ -0,0 +1,112 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include "absl/strings/internal/memutil.h"
|
16
|
+
|
17
|
+
#include <cstdlib>
|
18
|
+
|
19
|
+
namespace absl {
|
20
|
+
ABSL_NAMESPACE_BEGIN
|
21
|
+
namespace strings_internal {
|
22
|
+
|
23
|
+
int memcasecmp(const char* s1, const char* s2, size_t len) {
|
24
|
+
const unsigned char* us1 = reinterpret_cast<const unsigned char*>(s1);
|
25
|
+
const unsigned char* us2 = reinterpret_cast<const unsigned char*>(s2);
|
26
|
+
|
27
|
+
for (size_t i = 0; i < len; i++) {
|
28
|
+
const int diff =
|
29
|
+
int{static_cast<unsigned char>(absl::ascii_tolower(us1[i]))} -
|
30
|
+
int{static_cast<unsigned char>(absl::ascii_tolower(us2[i]))};
|
31
|
+
if (diff != 0) return diff;
|
32
|
+
}
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
char* memdup(const char* s, size_t slen) {
|
37
|
+
void* copy;
|
38
|
+
if ((copy = malloc(slen)) == nullptr) return nullptr;
|
39
|
+
memcpy(copy, s, slen);
|
40
|
+
return reinterpret_cast<char*>(copy);
|
41
|
+
}
|
42
|
+
|
43
|
+
char* memrchr(const char* s, int c, size_t slen) {
|
44
|
+
for (const char* e = s + slen - 1; e >= s; e--) {
|
45
|
+
if (*e == c) return const_cast<char*>(e);
|
46
|
+
}
|
47
|
+
return nullptr;
|
48
|
+
}
|
49
|
+
|
50
|
+
size_t memspn(const char* s, size_t slen, const char* accept) {
|
51
|
+
const char* p = s;
|
52
|
+
const char* spanp;
|
53
|
+
char c, sc;
|
54
|
+
|
55
|
+
cont:
|
56
|
+
c = *p++;
|
57
|
+
if (slen-- == 0) return p - 1 - s;
|
58
|
+
for (spanp = accept; (sc = *spanp++) != '\0';)
|
59
|
+
if (sc == c) goto cont;
|
60
|
+
return p - 1 - s;
|
61
|
+
}
|
62
|
+
|
63
|
+
size_t memcspn(const char* s, size_t slen, const char* reject) {
|
64
|
+
const char* p = s;
|
65
|
+
const char* spanp;
|
66
|
+
char c, sc;
|
67
|
+
|
68
|
+
while (slen-- != 0) {
|
69
|
+
c = *p++;
|
70
|
+
for (spanp = reject; (sc = *spanp++) != '\0';)
|
71
|
+
if (sc == c) return p - 1 - s;
|
72
|
+
}
|
73
|
+
return p - s;
|
74
|
+
}
|
75
|
+
|
76
|
+
char* mempbrk(const char* s, size_t slen, const char* accept) {
|
77
|
+
const char* scanp;
|
78
|
+
int sc;
|
79
|
+
|
80
|
+
for (; slen; ++s, --slen) {
|
81
|
+
for (scanp = accept; (sc = *scanp++) != '\0';)
|
82
|
+
if (sc == *s) return const_cast<char*>(s);
|
83
|
+
}
|
84
|
+
return nullptr;
|
85
|
+
}
|
86
|
+
|
87
|
+
// This is significantly faster for case-sensitive matches with very
|
88
|
+
// few possible matches. See unit test for benchmarks.
|
89
|
+
const char* memmatch(const char* phaystack, size_t haylen, const char* pneedle,
|
90
|
+
size_t neelen) {
|
91
|
+
if (0 == neelen) {
|
92
|
+
return phaystack; // even if haylen is 0
|
93
|
+
}
|
94
|
+
if (haylen < neelen) return nullptr;
|
95
|
+
|
96
|
+
const char* match;
|
97
|
+
const char* hayend = phaystack + haylen - neelen + 1;
|
98
|
+
// A static cast is used here to work around the fact that memchr returns
|
99
|
+
// a void* on Posix-compliant systems and const void* on Windows.
|
100
|
+
while ((match = static_cast<const char*>(
|
101
|
+
memchr(phaystack, pneedle[0], hayend - phaystack)))) {
|
102
|
+
if (memcmp(match, pneedle, neelen) == 0)
|
103
|
+
return match;
|
104
|
+
else
|
105
|
+
phaystack = match + 1;
|
106
|
+
}
|
107
|
+
return nullptr;
|
108
|
+
}
|
109
|
+
|
110
|
+
} // namespace strings_internal
|
111
|
+
ABSL_NAMESPACE_END
|
112
|
+
} // namespace absl
|