Coverage Report

Created: 2026-06-13 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/misc/hash.c
Line
Count
Source
1
/*
2
 * This file is part of mpv.
3
 *
4
 * mpv is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * mpv is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include <stdint.h>
19
20
#include <libavutil/hash.h>
21
22
#include "common/common.h"
23
#include "misc/hash.h"
24
25
bstr mp_hash_to_bstr(void *talloc_ctx, const uint8_t *data, size_t len, const char *algorithm)
26
555k
{
27
555k
    struct AVHashContext *ctx = NULL;
28
555k
    mp_require(av_hash_alloc(&ctx, algorithm) == 0);
29
555k
    int size = av_hash_get_size(ctx);
30
555k
    uint8_t hash[AV_HASH_MAX_SIZE] = {0};
31
32
555k
    av_hash_init(ctx);
33
555k
    av_hash_update(ctx, data, len);
34
555k
    av_hash_final(ctx, hash);
35
555k
    av_hash_freep(&ctx);
36
37
555k
    bstr ret = {0};
38
9.45M
    for (int n = 0; n < size; n++)
39
8.89M
        bstr_xappend_asprintf(talloc_ctx, &ret, "%02X", hash[n]);
40
555k
    return ret;
41
555k
}