• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22550237931

01 Mar 2026 06:56PM UTC coverage: 64.812% (-8.9%) from 73.687%
22550237931

Pull #14920

github

web-flow
Merge e05854a6d into 90823fa90
Pull Request #14920: draft: rust based configuration file parser and loader - v4

561 of 789 new or added lines in 4 files covered. (71.1%)

23225 existing lines in 498 files now uncovered.

131605 of 203055 relevant lines covered (64.81%)

2328818.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/util-lua-base64lib.c
1
/* Copyright (C) 2025 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
#include "suricata-common.h"
19
#include "util-lua-base64lib.h"
20
#include "util-validate.h"
21
#include "lauxlib.h"
22
#include "rust.h"
23

24
static int LuaBase64Encode(lua_State *L, SCBase64Mode mode)
UNCOV
25
{
×
UNCOV
26
    size_t input_len;
×
UNCOV
27
    const char *input = luaL_checklstring(L, 1, &input_len);
×
UNCOV
28
    size_t out_len = SCBase64EncodeBufferSize(input_len);
×
UNCOV
29
    char *output = SCCalloc(out_len + 1, sizeof(char));
×
UNCOV
30
    if (output == NULL) {
×
31
        return luaL_error(L, "malloc");
×
32
    }
×
UNCOV
33
    if (SCBase64EncodeWithMode((uint8_t *)input, (unsigned long)input_len, (u_char *)output,
×
UNCOV
34
                (unsigned long *)&out_len, mode) != 0) {
×
35
        SCFree(output);
×
36
        return luaL_error(L, "base64 encoding failed");
×
37
    }
×
UNCOV
38
    lua_pushstring(L, (const char *)output);
×
UNCOV
39
    SCFree(output);
×
40

UNCOV
41
    return 1;
×
UNCOV
42
}
×
43

44
static int LuaBase64EncodeStandard(lua_State *L)
UNCOV
45
{
×
UNCOV
46
    return LuaBase64Encode(L, SCBase64ModeStrict);
×
UNCOV
47
}
×
48

49
static int LuaBase64EncodeStandardNoPad(lua_State *L)
UNCOV
50
{
×
UNCOV
51
    return LuaBase64Encode(L, SCBase64ModeNoPad);
×
UNCOV
52
}
×
53

54
static int LuaBase64Decode(lua_State *L, SCBase64Mode mode)
UNCOV
55
{
×
UNCOV
56
    size_t input_len;
×
UNCOV
57
    const char *input = luaL_checklstring(L, 1, &input_len);
×
UNCOV
58
    char *output = SCCalloc(input_len, sizeof(char));
×
UNCOV
59
    if (output == NULL) {
×
60
        return luaL_error(L, "malloc");
×
61
    }
×
UNCOV
62
    uint32_t n = SCBase64Decode((uint8_t *)input, (uintptr_t)input_len, mode, (uint8_t *)output);
×
UNCOV
63
    if (n == 0) {
×
64
        SCFree(output);
×
65
        return luaL_error(L, "base64 decoding failed");
×
66
    }
×
UNCOV
67
    DEBUG_VALIDATE_BUG_ON(n > input_len);
×
UNCOV
68
    output[n] = '\0';
×
UNCOV
69
    lua_pushstring(L, (const char *)output);
×
UNCOV
70
    SCFree(output);
×
71

UNCOV
72
    return 1;
×
UNCOV
73
}
×
74

75
static int LuaBase64DecodeStandard(lua_State *L)
UNCOV
76
{
×
UNCOV
77
    return LuaBase64Decode(L, SCBase64ModeStrict);
×
UNCOV
78
}
×
79

80
static int LuaBase64DecodeStandardNoPad(lua_State *L)
UNCOV
81
{
×
UNCOV
82
    return LuaBase64Decode(L, SCBase64ModeNoPad);
×
UNCOV
83
}
×
84

85
static int LuaBase64DecodeStandardPadOpt(lua_State *L)
UNCOV
86
{
×
UNCOV
87
    return LuaBase64Decode(L, SCBase64ModePadOpt);
×
UNCOV
88
}
×
89

90
static int LuaBase64DecodeRFC2045(lua_State *L)
UNCOV
91
{
×
UNCOV
92
    return LuaBase64Decode(L, SCBase64ModeRFC2045);
×
UNCOV
93
}
×
94

95
static int LuaBase64DecodeRFC4648(lua_State *L)
UNCOV
96
{
×
UNCOV
97
    return LuaBase64Decode(L, SCBase64ModeRFC4648);
×
UNCOV
98
}
×
99

100
static const struct luaL_Reg base64lib[] = {
101
    // clang-format off
102
    { "encode", LuaBase64EncodeStandard },
103
    { "encode_nopad", LuaBase64EncodeStandardNoPad },
104
    { "decode", LuaBase64DecodeStandard },
105
    { "decode_nopad", LuaBase64DecodeStandardNoPad },
106
    { "decode_padopt", LuaBase64DecodeStandardPadOpt },
107
    { "decode_rfc2045", LuaBase64DecodeRFC2045 },
108
    { "decode_rfc4648", LuaBase64DecodeRFC4648 },
109
    { NULL, NULL },
110
    // clang-format on
111
};
112

113
int SCLuaLoadBase64Lib(lua_State *L)
UNCOV
114
{
×
UNCOV
115
    luaL_newlib(L, base64lib);
×
116

UNCOV
117
    return 1;
×
UNCOV
118
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc