Skip to content

Conversation

@sbiscigl
Copy link
Contributor

@sbiscigl sbiscigl commented Nov 5, 2024

Description of changes:

Adds a crypto utility class for CRC64 from CRT, refactors CRC32 related crypto factories to avoid DRY-ing.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


static std::shared_ptr<HashFactory>& GetCRC64Factory()
{
static std::shared_ptr<HashFactory> s_CRC64Factory(nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

how does it work with our custom memory management?

Copy link
Contributor Author

@sbiscigl sbiscigl Nov 5, 2024

Choose a reason for hiding this comment

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

its gets assigned when we call its factory, it follows the same call path as CRC32 does. i.e.

create accessor for static factory

static std::shared_ptr<HashFactory>& GetCRC32Factory()
{
    static std::shared_ptr<HashFactory> s_CRC32Factory(nullptr);
    return s_CRC32Factory;
}

then is assigned during the init crypto call

if(!GetCRC32Factory())
{
  GetCRC32Factory() = Aws::MakeShared<DefaultCRC32Factory>(s_allocationTag);
}

then is set to nullptr before deleting

if(GetCRC32CFactory())
{
  GetCRC32Factory() = nullptr;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

OMG, okay.

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 changing this pattern and avoiding static state would be a larger change than this, but I agree something that should be done as part of some future "eliminate static state" task

@sbiscigl sbiscigl force-pushed the crc64 branch 2 times, most recently from 294b25b to 986461e Compare November 5, 2024 01:10
m_hashImpl->Update(buffer, bufferSize);
}

HashResult CRC64::GetHash()
Copy link
Contributor

Choose a reason for hiding this comment

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

get apis typically should be marked const for correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cant because the original API is not, and we cannot change it without breaking backwards compatibilty.

uint8_t streamBuffer[Aws::Utils::Crypto::Hash::INTERNAL_HASH_STREAM_BUFFER_SIZE];
while (stream.good())
{
stream.read(reinterpret_cast<char*>(streamBuffer), Aws::Utils::Crypto::Hash::INTERNAL_HASH_STREAM_BUFFER_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

better to use
while (stream.read(reinterpret_cast<char*>(streamBuffer), Aws::Utils::Crypto::Hash::INTERNAL_HASH_STREAM_BUFFER_SIZE)) {
to handle end of stream errors more cleanly

Copy link
Contributor Author

@sbiscigl sbiscigl Nov 5, 2024

Choose a reason for hiding this comment

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

this actually causes the integration tests to fail, so there is a behavior difference between stream.good and if(stream.read). this is also how it is currently done. this is just moving it to a non copied pasted place

@sbera87
Copy link
Contributor

sbera87 commented Nov 5, 2024

to format code , please use the following cmd
git diff -U0 --no-color main <your branch> -- . ':!generated/' | python3 /opt/homebrew/opt/llvm/share/clang/clang-format-diff.py -p1 -i

}

void CRC64::Update(unsigned char* buffer, size_t bufferSize)
{
Copy link
Contributor

@sbera87 sbera87 Nov 5, 2024

Choose a reason for hiding this comment

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

null check?
also constness of the ptr, unsigned char* const buffer ?

Copy link
Contributor Author

@sbiscigl sbiscigl Nov 5, 2024

Choose a reason for hiding this comment

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

can add null check, cant change constness because the original API is not, and we cannot change it without breaking backwards compatibilty.

@sbiscigl
Copy link
Contributor Author

sbiscigl commented Nov 5, 2024

to format code , please use the following cmd git diff -U0 --no-color main <your branch> -- . ':!generated/' | python3 /opt/homebrew/opt/llvm/share/clang/clang-format-diff.py -p1 -i

you didnt commit a .clang-format in pull/3169. once we add a clang format file we can adhere to that check, but right now since there is no format file, we are not formatting against any known format

@sbera87
Copy link
Contributor

sbera87 commented Nov 5, 2024

to format code , please use the following cmd git diff -U0 --no-color main <your branch> -- . ':!generated/' | python3 /opt/homebrew/opt/llvm/share/clang/clang-format-diff.py -p1 -i

you didnt commit a .clang-format in pull/3169. once we add a clang format file we can adhere to that check, but right now since there is no format file, we are not formatting against any known format

using the clang-format-diff specifying the style doesn't need the clang_format file. On can provide the file for customizations but its not needed per documentation

@sbiscigl
Copy link
Contributor Author

sbiscigl commented Nov 5, 2024

using the clang-format-diff specifying the style doesn't need the clang_format file. On can provide the file for customizations but its not needed per documentation

we're formatting against a unknown default format then, im against this check until we add a defined file, otherwise we dont know what style we are formatting against as none is specified.

@sbiscigl sbiscigl force-pushed the crc64 branch 2 times, most recently from 21e631c to 8d0703d Compare November 5, 2024 15:46
@sbera87 sbera87 self-requested a review November 5, 2024 16:12
@sbera87
Copy link
Contributor

sbera87 commented Nov 5, 2024

lgtm

@sbiscigl sbiscigl marked this pull request as ready for review November 5, 2024 18:38
@sbiscigl sbiscigl merged commit d6594f9 into main Nov 5, 2024
5 checks passed
@sbiscigl sbiscigl deleted the crc64 branch November 5, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants