Skip to content

Conversation

@dreamer-dead
Copy link
Contributor

Main intent of this PR is to simplify hashMultiFromFile a little bit:

  • Remove shared_ptr completely, because there are no clients that can share the pointer, all usage is localised in hashMultiFromFile function.
  • Remove map (or even unordered_map), just because we don't need to address map elements by keys.
  • Add few std::move calls to help the compiler better understand what is going on.

To achieve that I have to add new move-ctor for the Hash class. Hope that this is not forbidden.
In other way, this behaviour can be done with std::unique_ptr<Hash>.

PTAL.

@dreamer-dead dreamer-dead requested review from a team as code owners April 18, 2023 08:55
} else if (encoding_ == HASH_ENCODING_TYPE_BASE64) {
std::stringstream digest;
for (size_t i = 0; i < length_; i++) {
digest << hash[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it seems, operator<< should append unsigned char to the stream as a char. So the whole iteration can be simplified with just a copy.
The copy itself can be avoided, but this will require a few casts that look bad.

Looks like I missed a test for this case, will add.

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've checked new tests with HASH_ENCODING_TYPE_BASE64 with and wthout this particular change and don't see any difference in results.

@mike-myers-tob mike-myers-tob changed the title Simplify hashMultiFromFile function Simplify hashMultiFromFile function May 9, 2023
@mike-myers-tob mike-myers-tob added refactor Related to osquery code refactoring ready for review Pull requests that are ready to be reviewed by a maintainer labels May 9, 2023
@directionless
Copy link
Member

Looks okay to me, any of the more c folks want to weigh in? (@alessandrogario @Smjert @marcosd4h )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Pull requests that are ready to be reviewed by a maintainer refactor Related to osquery code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants