New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rgw: add variadic string join for s3 signature generation #15678
Conversation
src/rgw/rgw_string.h
Outdated
// specializations for null-terminated string literals | ||
template <std::size_t N> | ||
struct string_traits<const char[N]> { | ||
static constexpr size_t size(const char (&s)[N]) { return N-1; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives different results than std::strlen
for strings that have \0
in the middle. However, I think we can live with that for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i think i prefer strlen()
here too. that's what the boost::string_view()
constructor does for string literals, so this would make string_size()
more consistent with those conversions in append/join
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We share absolutely the same feeling. The issue is that astrlen
implementation isn't mandated to be conestexpr
-capable. Clang was complaining about that today. :-(
struct ltstr_nocase | ||
{ | ||
bool operator()(const string& s1, const string& s2) const | ||
bool operator()(const std::string& s1, const std::string& s2) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
.append(AWS4_EMPTY_PAYLOAD_HASH, empty_hash_len) | ||
.append("\n", std::strlen("\n")) | ||
.append(payload_hash); | ||
const auto string_to_sign = string_join_reserve("\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faster AND cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure it's actually faster, as it was already calculating the total size for string::reserve()
. i just think the variadic version is less error-prone by doing the size calculation for you
const size_t total_len = algorithm_len + date.length() + \ | ||
credential_scope.length() + prev_chunk_signature.length() + \ | ||
empty_hash_len + payload_hash.length() + std::strlen("\n") * 5; | ||
const auto string_to_sign = create_n_reserve<std::string>(total_len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely drop create_n_reserve
from rgw_string
. It doesn't seem to be used anywhere else.
this allows it to be included as a standalone header, without relying on other headers to pull in namespace std Signed-off-by: Casey Bodley <cbodley@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Libertine Gazelles Try Multiplication
.append(AWS4_EMPTY_PAYLOAD_HASH, empty_hash_len) | ||
.append("\n", std::strlen("\n")) | ||
.append(payload_hash); | ||
const auto string_to_sign = string_join_reserve("\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faster AND cleaner.
these variadic functions are able to calculate the total length of the given string arguments for std::string::reserve(). string arguments can be c strings, string literals, or any string class that provides a .size(), .begin(), and .end() Signed-off-by: Casey Bodley <cbodley@redhat.com>
Signed-off-by: Casey Bodley <cbodley@redhat.com>
Signed-off-by: Casey Bodley <cbodley@redhat.com>
Signed-off-by: Casey Bodley <cbodley@redhat.com>
e0279a0
to
195cc99
Compare
rebased over constexpr changes, updated with |
jenkins test this please |
1 similar comment
jenkins test this please |
No description provided.