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

Common/Crypto/SHA1: Use span and string_view for Context::Update() #12915

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

AdmiralCurtiss
Copy link
Contributor

I also tried updating the CalculateDigest() below to use spans but for some reason the compiler is bad at automatically deducing the template type if you do that. Oh well, this is still worthwhile on its own IMO.

template <typename T>
inline Digest CalculateDigest(std::span<const T> msg)
{
  static_assert(std::is_trivially_copyable_v<T>);
  ASSERT(std::numeric_limits<size_t>::max() / sizeof(T) >= msg.size());
  return CalculateDigest(reinterpret_cast<const u8*>(msg.data()), sizeof(T) * msg.size());
}
C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): error C2665: 'Common::SHA1::CalculateDigest': no overloaded function could convert all the argument types
  C:\dolphin\Source\Core\Common/Crypto/SHA1.h(48): note: could be 'Common::SHA1::Digest Common::SHA1::CalculateDigest(const std::string_view &)'
  C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): note: 'Common::SHA1::Digest Common::SHA1::CalculateDigest(const std::string_view &)': cannot convert argument 1 from 'const std::vector<u8,std::allocator<u8>>' to 'const std::string_view &'
  C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): note: Reason: cannot convert from 'const std::vector<u8,std::allocator<u8>>' to 'const std::string_view'
  C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  C:\dolphin\Source\Core\Common/Crypto/SHA1.h(41): note: or       'Common::SHA1::Digest Common::SHA1::CalculateDigest(std::span<const T,18446744073709551615>)'
  C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): note: 'Common::SHA1::Digest Common::SHA1::CalculateDigest(std::span<const T,18446744073709551615>)': could not deduce template argument for 'std::span<const T,18446744073709551615>' from 'const std::vector<u8,std::allocator<u8>>'
  C:\dolphin\Source\Core\Core\IOS\ES\Identity.cpp(194): note: while trying to match the argument list '(const std::vector<u8,std::allocator<u8>>)'

@AdmiralCurtiss AdmiralCurtiss merged commit 6ddfdc1 into dolphin-emu:master Jul 5, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants