Skip to content
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

Merged
merged 5 commits into from Jun 16, 2017

Conversation

cbodley
Copy link
Contributor

@cbodley cbodley commented Jun 14, 2017

No description provided.

// 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; }
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faster AND cleaner.

Copy link
Contributor Author

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)
Copy link
Contributor

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>
Copy link
Contributor

@adamemerson adamemerson left a 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",
Copy link
Contributor

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>
@cbodley cbodley changed the title [RFC] rgw: add variadic string join for s3 signature generation rgw: add variadic string join for s3 signature generation Jun 14, 2017
@cbodley
Copy link
Contributor Author

cbodley commented Jun 14, 2017

rebased over constexpr changes, updated with strlen() for the array specializations, and removed create_n_reserve()

@cbodley
Copy link
Contributor Author

cbodley commented Jun 14, 2017

jenkins test this please

1 similar comment
@cbodley
Copy link
Contributor Author

cbodley commented Jun 14, 2017

jenkins test this please

@cbodley cbodley merged commit 4c22420 into ceph:master Jun 16, 2017
@cbodley cbodley deleted the wip-rgw-string-join branch June 16, 2017 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants