Coverage Report

Created: 2026-10-13 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pidgin/libpurple/ciphers/gchecksum.c
Line
Count
Source
1
#include <cipher.h>
2
3
#if GLIB_CHECK_VERSION(2,16,0)
4
5
static void
6
purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type)
7
0
{
8
0
    GChecksum *checksum;
9
10
0
    checksum = g_checksum_new(type);
11
0
    purple_cipher_context_set_data(context, checksum);
12
0
}
13
14
static void
15
purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type)
16
0
{
17
0
    GChecksum *checksum;
18
19
0
    checksum = purple_cipher_context_get_data(context);
20
0
    g_return_if_fail(checksum != NULL);
21
22
0
#if GLIB_CHECK_VERSION(2,18,0)
23
0
    g_checksum_reset(checksum);
24
#else
25
    g_checksum_free(checksum);
26
    checksum = g_checksum_new(type);
27
    purple_cipher_context_set_data(context, checksum);
28
#endif
29
0
}
30
31
static void
32
purple_g_checksum_uninit(PurpleCipherContext *context)
33
0
{
34
0
    GChecksum *checksum;
35
36
0
    checksum = purple_cipher_context_get_data(context);
37
0
    g_return_if_fail(checksum != NULL);
38
39
0
    g_checksum_free(checksum);
40
0
}
41
42
static void
43
purple_g_checksum_append(PurpleCipherContext *context, const guchar *data,
44
                         gsize len)
45
0
{
46
0
    GChecksum *checksum;
47
48
0
    checksum = purple_cipher_context_get_data(context);
49
0
    g_return_if_fail(checksum != NULL);
50
51
0
    while (len >= G_MAXSSIZE) {
52
0
        g_checksum_update(checksum, data, G_MAXSSIZE);
53
0
        len -= G_MAXSSIZE;
54
0
        data += G_MAXSSIZE;
55
0
    }
56
57
0
    if (len)
58
0
        g_checksum_update(checksum, data, len);
59
0
}
60
61
static gboolean
62
purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type,
63
                         gsize len, guchar *digest, gsize *out_len)
64
0
{
65
0
    GChecksum *checksum;
66
0
    const gssize required_length = g_checksum_type_get_length(type);
67
68
0
    checksum = purple_cipher_context_get_data(context);
69
70
0
    g_return_val_if_fail(len >= required_length, FALSE);
71
0
    g_return_val_if_fail(checksum != NULL, FALSE);
72
73
0
    g_checksum_get_digest(checksum, digest, &len);
74
75
0
    purple_cipher_context_reset(context, NULL);
76
77
0
    if (out_len)
78
0
        *out_len = len;
79
80
0
    return TRUE;
81
0
}
82
83
/******************************************************************************
84
 * Macros
85
 *****************************************************************************/
86
#define PURPLE_G_CHECKSUM_IMPLEMENTATION(lower, camel, type, block_size) \
87
  static size_t \
88
0
  lower##_get_block_size(PurpleCipherContext *context) { \
89
0
    return (block_size); \
90
0
  } \
Unexecuted instantiation: gchecksum.c:md5_get_block_size
Unexecuted instantiation: gchecksum.c:sha1_get_block_size
Unexecuted instantiation: gchecksum.c:sha256_get_block_size
91
  \
92
  static void \
93
0
  lower##_init(PurpleCipherContext *context, gpointer extra) { \
94
0
    purple_g_checksum_init(context, (type)); \
95
0
  } \
Unexecuted instantiation: gchecksum.c:md5_init
Unexecuted instantiation: gchecksum.c:sha1_init
Unexecuted instantiation: gchecksum.c:sha256_init
96
  \
97
  static void \
98
0
  lower##_reset(PurpleCipherContext *context, gpointer extra) { \
99
0
    purple_g_checksum_reset(context, (type)); \
100
0
  } \
Unexecuted instantiation: gchecksum.c:md5_reset
Unexecuted instantiation: gchecksum.c:sha1_reset
Unexecuted instantiation: gchecksum.c:sha256_reset
101
  \
102
  static gboolean \
103
  lower##_digest(PurpleCipherContext *context, gsize in_len, \
104
                   guchar digest[], size_t *out_len) \
105
0
  { \
106
0
    return purple_g_checksum_digest(context, (type), in_len, digest, \
107
0
                                    out_len); \
108
0
  } \
Unexecuted instantiation: gchecksum.c:md5_digest
Unexecuted instantiation: gchecksum.c:sha1_digest
Unexecuted instantiation: gchecksum.c:sha256_digest
109
  \
110
  static PurpleCipherOps camel##Ops = { \
111
    NULL,                     /* Set option */       \
112
    NULL,                     /* Get option */       \
113
    lower##_init,             /* init */             \
114
    lower##_reset,            /* reset */            \
115
    purple_g_checksum_uninit, /* uninit */           \
116
    NULL,                     /* set iv */           \
117
    purple_g_checksum_append, /* append */           \
118
    lower##_digest,           /* digest */           \
119
    NULL,                     /* encrypt */          \
120
    NULL,                     /* decrypt */          \
121
    NULL,                     /* set salt */         \
122
    NULL,                     /* get salt size */    \
123
    NULL,                     /* set key */          \
124
    NULL,                     /* get key size */     \
125
    NULL,                     /* set batch mode */   \
126
    NULL,                     /* get batch mode */   \
127
    lower##_get_block_size,   /* get block size */   \
128
    NULL                      /* set key with len */ \
129
  }; \
130
  \
131
  PurpleCipherOps * \
132
0
  purple_##lower##_cipher_get_ops(void) { \
133
0
    return &camel##Ops; \
134
0
  }
Unexecuted instantiation: purple_md5_cipher_get_ops
Unexecuted instantiation: purple_sha1_cipher_get_ops
Unexecuted instantiation: purple_sha256_cipher_get_ops
135
136
/******************************************************************************
137
 * Macro Expansion
138
 *****************************************************************************/
139
PURPLE_G_CHECKSUM_IMPLEMENTATION(md5, MD5, G_CHECKSUM_MD5, 64);
140
PURPLE_G_CHECKSUM_IMPLEMENTATION(sha1, SHA1, G_CHECKSUM_SHA1, 64);
141
PURPLE_G_CHECKSUM_IMPLEMENTATION(sha256, SHA256, G_CHECKSUM_SHA256, 64);
142
143
#endif /* GLIB_CHECK_VERSION(2,16,0) */
144