Check emoji cache signature asynchronously.

This commit is contained in:
John Preston 2018-10-15 07:57:03 +03:00
parent b847c8424a
commit 2b2b9c2f03
1 changed files with 18 additions and 5 deletions

View File

@ -145,18 +145,31 @@ QImage LoadFromFile(int size, int index) {
height, height,
QImage::Format_ARGB32_Premultiplied); QImage::Format_ARGB32_Premultiplied);
Assert(result.bytesPerLine() == width * 4); Assert(result.bytesPerLine() == width * 4);
auto data = bytes::make_span( const auto data = bytes::make_span(
reinterpret_cast<bytes::type*>(result.bits()), reinterpret_cast<bytes::type*>(result.bits()),
width * height * 4); width * height * 4);
bytes::type signature[openssl::kSha256Size] = { bytes::type() }; auto signature = bytes::vector(openssl::kSha256Size);
if (!read(data) if (!read(data)
|| !read(signature) || !read(signature)
|| (bytes::compare( //|| (bytes::compare(
signature, // signature,
openssl::Sha256(bytes::make_span(header), data)) != 0) // openssl::Sha256(bytes::make_span(header), data)) != 0)
|| false) { || false) {
return QImage(); return QImage();
} }
crl::async([=, signature = std::move(signature)] {
// This should not happen (invalid signature),
// so we delay this check and fix only the next launch.
const auto data = bytes::make_span(
reinterpret_cast<const bytes::type*>(result.bits()),
width * height * 4);
const auto result = bytes::compare(
signature,
openssl::Sha256(bytes::make_span(header), data));
if (result != 0) {
QFile(CacheFilePath(size, index)).remove();
}
});
return result; return result;
} }