lib/crypto/MD5: add option to use libavutil instead of libgcrypt

This commit is contained in:
Max Kellermann 2019-08-14 18:56:10 +02:00
parent 433e18b247
commit 5c550e8b33
4 changed files with 29 additions and 2 deletions

View File

@ -28,20 +28,38 @@
*/
#include "MD5.hxx"
#include "util/HexFormat.hxx"
#include "config.h"
#ifdef HAVE_LIBAVUTIL
extern "C" {
#include <libavutil/md5.h>
}
#else
#include "lib/gcrypt/MD5.hxx"
#include "lib/gcrypt/Init.hxx"
#include "util/HexFormat.hxx"
#endif
void
GlobalInitMD5() noexcept
{
#ifdef HAVE_LIBAVUTIL
/* no initialization necessary */
#else
Gcrypt::Init();
#endif
}
std::array<uint8_t, 16>
MD5(ConstBuffer<void> input) noexcept
{
#ifdef HAVE_LIBAVUTIL
std::array<uint8_t, 16> result;
av_md5_sum(&result.front(), (const uint8_t *)input.data, input.size);
return result;
#else
return Gcrypt::MD5(input);
#endif
}
StringBuffer<33>

View File

@ -1,9 +1,10 @@
if gcrypt_dep.found()
if libavutil_dep.found() or gcrypt_dep.found()
crypto_md5 = static_library(
'crypto_md5',
'MD5.cxx',
include_directories: inc,
dependencies: [
libavutil_dep,
gcrypt_dep,
],
)

View File

@ -1,6 +1,7 @@
libavformat_dep = dependency('libavformat', version: '>= 57.40', required: get_option('ffmpeg'))
libavcodec_dep = dependency('libavcodec', version: '>= 57.48', required: get_option('ffmpeg'))
libavutil_dep = dependency('libavutil', version: '>= 55.27', required: get_option('ffmpeg'))
conf.set('HAVE_LIBAVUTIL', libavutil_dep.found())
enable_ffmpeg = libavformat_dep.found() and libavcodec_dep.found() and libavutil_dep.found()
conf.set('ENABLE_FFMPEG', enable_ffmpeg)

View File

@ -1,3 +1,10 @@
if libavutil_dep.found()
# if we have FFmpeg, we can use its MD5 implementation and we don't
# need libgcrypt
gcrypt_dep = dependency('', required: false)
subdir_done()
endif
# Since version 0.49.0 Meson has native libgcrypt dependency support, which has
# the advantage over find_library() as it uses libgcrypt-config to query the
# required linker flags.