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

mavlink / MAVSDK / 10748697329

07 Sep 2024 04:40AM UTC coverage: 38.056% (-0.01%) from 38.066%
10748697329

Pull #2393

github

web-flow
Merge c49dfa278 into 6106bf78c
Pull Request #2393: CI: a few fixes and adding newer compilers

11448 of 30082 relevant lines covered (38.06%)

261.81 hits per line

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

0.0
/src/mavsdk/core/base64.cpp
1
#include "base64.h"
2

3
namespace mavsdk {
4

5
static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6
                                        "abcdefghijklmnopqrstuvwxyz"
7
                                        "0123456789+/";
8

9
static inline bool is_base64(uint8_t c)
×
10
{
11
    return (isalnum(c) || (c == '+') || (c == '/'));
×
12
}
13

14
std::string base64_encode(std::vector<uint8_t>& raw)
×
15
{
16
    uint8_t* buf = raw.data();
×
17
    size_t bufLen = raw.size();
×
18

19
    std::string ret;
×
20
    int i = 0;
×
21
    int j = 0;
×
22
    uint8_t char_array_3[3];
×
23
    uint8_t char_array_4[4];
×
24

25
    while (bufLen--) {
×
26
        char_array_3[i++] = *(buf++);
×
27
        if (i == 3) {
×
28
            char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
×
29
            char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
×
30
            char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
×
31
            char_array_4[3] = char_array_3[2] & 0x3f;
×
32

33
            for (i = 0; (i < 4); i++)
×
34
                ret += base64_chars[char_array_4[i]];
×
35
            i = 0;
×
36
        }
37
    }
38

39
    if (i) {
×
40
        for (j = i; j < 3; j++)
×
41
            char_array_3[j] = '\0';
×
42

43
        char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
×
44
        char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
×
45
        char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
×
46
        char_array_4[3] = char_array_3[2] & 0x3f;
×
47

48
        for (j = 0; (j < i + 1); j++)
×
49
            ret += base64_chars[char_array_4[j]];
×
50

51
        while ((i++ < 3))
×
52
            ret += '=';
×
53
    }
54

55
    return ret;
×
56
}
57

58
std::vector<uint8_t> base64_decode(std::string const& encoded_string)
×
59
{
60
    int in_len = encoded_string.size();
×
61
    int i = 0;
×
62
    int j = 0;
×
63
    int in_ = 0;
×
64
    uint8_t char_array_4[4], char_array_3[3];
×
65
    std::vector<uint8_t> ret;
×
66

67
    while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
×
68
        char_array_4[i++] = encoded_string[in_];
×
69
        in_++;
×
70
        if (i == 4) {
×
71
            for (i = 0; i < 4; i++)
×
72
                char_array_4[i] = base64_chars.find(char_array_4[i]);
×
73

74
            char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
×
75
            char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
×
76
            char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
×
77

78
            for (i = 0; (i < 3); i++)
×
79
                ret.push_back(char_array_3[i]);
×
80
            i = 0;
×
81
        }
82
    }
83

84
    if (i) {
×
85
        for (j = i; j < 4; j++)
×
86
            char_array_4[j] = 0;
×
87

88
        for (j = 0; j < 4; j++)
×
89
            char_array_4[j] = base64_chars.find(char_array_4[j]);
×
90

91
        char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
×
92
        char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
×
93
        char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
×
94

95
        for (j = 0; (j < i - 1); j++)
×
96
            ret.push_back(char_array_3[j]);
×
97
    }
98

99
    return ret;
×
100
}
101

102
} // namespace mavsdk
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

© 2025 Coveralls, Inc