Coverage Report

Created: 2023-03-26 07:38

/src/yara/libyara/tlshc/tlsh.c
Line
Count
Source (jump to first uncovered line)
1
#include <stdlib.h>
2
#include <tlshc/tlsh.h>
3
#include "tlsh_impl.h"
4
5
Tlsh* tlsh_new()
6
0
{
7
0
  Tlsh* tlsh = malloc(sizeof(Tlsh));
8
0
  if (!tlsh)
9
0
    return NULL;
10
11
0
  tlsh->impl = tlsh_impl_new();
12
0
  if (!tlsh->impl)
13
0
  {
14
0
    free(tlsh);
15
0
    return NULL;
16
0
  }
17
18
0
  return tlsh;
19
0
}
20
21
void tlsh_free(Tlsh* tlsh)
22
0
{
23
0
  if (tlsh)
24
0
  {
25
0
    tlsh_impl_free(tlsh->impl);
26
0
    free(tlsh);
27
0
  }
28
0
}
29
30
int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len)
31
0
{
32
0
  int tlsh_option = 0;
33
0
  if (tlsh->impl)
34
0
  {
35
0
    int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option);
36
0
    if (res)
37
0
    {
38
0
      return 1;
39
0
    }
40
0
  }
41
42
0
  return 0;
43
0
}
44
45
void tlsh_reset(Tlsh* tlsh)
46
0
{
47
0
  if (tlsh->impl)
48
0
    tlsh_impl_reset(tlsh->impl);
49
0
}
50
51
int tlsh_final(
52
    Tlsh* tlsh,
53
    const unsigned char* data,
54
    unsigned int len,
55
    int tlsh_option)
56
0
{
57
0
  if (tlsh->impl)
58
0
  {
59
0
    if ((data != NULL) && (len > 0))
60
0
    {
61
0
      int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option);
62
0
      if (res)
63
0
      {
64
0
        return 1;
65
0
      }
66
0
    }
67
68
0
    tlsh_impl_final(tlsh->impl, tlsh_option);
69
0
  }
70
71
0
  return 0;
72
0
}
73
74
const char* tlsh_get_hash(Tlsh* tlsh, bool showvers)
75
0
{
76
0
  if (tlsh->impl)
77
0
    return tlsh_impl_hash(tlsh->impl, showvers);
78
0
  else
79
0
    return "";
80
0
}