Use the system's sha2 library if it's available. Fixes #4217
This commit is contained in:
parent
1c1ea31f49
commit
7b651136d8
@ -385,10 +385,19 @@ if(GMOCK_INCLUDE_DIRS)
|
||||
endif(GTEST_INCLUDE_DIRS)
|
||||
endif(GMOCK_INCLUDE_DIRS)
|
||||
|
||||
# Never use the system's sha2.
|
||||
add_subdirectory(3rdparty/sha2)
|
||||
set(SHA2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/sha2)
|
||||
set(SHA2_LIBRARIES sha2)
|
||||
# Use the system's sha2 if it's available.
|
||||
find_path(SHA2_INCLUDE_DIRS sha2.h)
|
||||
find_library(SHA2_LIBRARIES sha2)
|
||||
if(SHA2_LIBRARIES AND SHA2_INCLUDE_DIRS)
|
||||
message(STATUS "Using system sha2 library")
|
||||
set(USE_SYSTEM_SHA2 ON)
|
||||
else()
|
||||
message(STATUS "Using builtin sha2 library")
|
||||
set(USE_SYSTEM_SHA2 OFF)
|
||||
add_subdirectory(3rdparty/sha2)
|
||||
set(SHA2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/sha2)
|
||||
set(SHA2_LIBRARIES sha2)
|
||||
endif()
|
||||
|
||||
# Use our 3rdparty chromaprint if a system one wasn't found
|
||||
if(NOT CHROMAPRINT_FOUND)
|
||||
|
@ -45,5 +45,6 @@
|
||||
#cmakedefine TAGLIB_HAS_OPUS
|
||||
#cmakedefine USE_INSTALL_PREFIX
|
||||
#cmakedefine USE_SYSTEM_PROJECTM
|
||||
#cmakedefine USE_SYSTEM_SHA2
|
||||
|
||||
#endif // CONFIG_H_IN
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/logging.h"
|
||||
#include "config.h"
|
||||
#include "timeconstants.h"
|
||||
|
||||
#include "sha2.h"
|
||||
@ -453,15 +454,22 @@ QByteArray HmacSha1(const QByteArray& key, const QByteArray& data) {
|
||||
}
|
||||
|
||||
QByteArray Sha256(const QByteArray& data) {
|
||||
clementine_sha2::SHA256_CTX context;
|
||||
clementine_sha2::SHA256_Init(&context);
|
||||
clementine_sha2::SHA256_Update(
|
||||
#ifndef USE_SYSTEM_SHA2
|
||||
using clementine_sha2::SHA256_CTX;
|
||||
using clementine_sha2::SHA256_Init;
|
||||
using clementine_sha2::SHA256_Update;
|
||||
using clementine_sha2::SHA256_Final;
|
||||
using clementine_sha2::SHA256_DIGEST_LENGTH;
|
||||
#endif
|
||||
|
||||
SHA256_CTX context;
|
||||
SHA256_Init(&context);
|
||||
SHA256_Update(
|
||||
&context, reinterpret_cast<const quint8*>(data.constData()),
|
||||
data.length());
|
||||
|
||||
QByteArray ret(clementine_sha2::SHA256_DIGEST_LENGTH, '\0');
|
||||
clementine_sha2::SHA256_Final(reinterpret_cast<quint8*>(ret.data()),
|
||||
&context);
|
||||
QByteArray ret(SHA256_DIGEST_LENGTH, '\0');
|
||||
SHA256_Final(reinterpret_cast<quint8*>(ret.data()), &context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user