diff options
author | Derek Mauro <dmauro@google.com> | 2024-02-05 18:31:36 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-05 18:32:37 -0800 |
commit | 0e289dc594da4b30eb03cb7cb2aa097f5d5f6eb5 (patch) | |
tree | cbdd9e5f0b6a31d006a960bf1799afd325dfd73c /absl/strings/escaping.h | |
parent | ddcf8be90575d494e40fcd4e0c408f0237efe0da (diff) |
Add a version of absl::HexStringToBytes() that returns a bool
to validate that the input was actually valid hexadecimal data.
Mark the version of absl::HexStringToBytes() that does not validate
the input as deprecated.
Fixes #141
PiperOrigin-RevId: 604495678
Change-Id: Iac3020c33c9dbc6d8e31a43b746783fb345edaa7
Diffstat (limited to 'absl/strings/escaping.h')
-rw-r--r-- | absl/strings/escaping.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/absl/strings/escaping.h b/absl/strings/escaping.h index 8f980178..3f34fbfc 100644 --- a/absl/strings/escaping.h +++ b/absl/strings/escaping.h @@ -27,6 +27,7 @@ #include <string> #include <vector> +#include "absl/base/attributes.h" #include "absl/base/macros.h" #include "absl/base/nullability.h" #include "absl/strings/ascii.h" @@ -158,8 +159,19 @@ bool WebSafeBase64Unescape(absl::string_view src, // HexStringToBytes() // +// Converts the hexadecimal encoded data in `hex` into raw bytes in the `bytes` +// output string. If `hex` does not consist of valid hexadecimal data, this +// function returns false and leaves `bytes` in an unspecified state. Returns +// true on success. +ABSL_MUST_USE_RESULT bool HexStringToBytes(absl::string_view hex, + absl::Nonnull<std::string*> bytes); + +// HexStringToBytes() +// // Converts an ASCII hex string into bytes, returning binary data of length -// `from.size()/2`. +// `from.size()/2`. The input must be valid hexadecimal data, otherwise the +// return value is unspecified. +ABSL_DEPRECATED("Use the HexStringToBytes() that returns a bool") std::string HexStringToBytes(absl::string_view from); // BytesToHexString() |