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

mendersoftware / mender / 969241802

16 Aug 2023 08:29AM UTC coverage: 79.019% (+0.2%) from 78.825%
969241802

push

gitlab-ci

oleorhagen
chore(crypto): Make the PrivateKey constructor public

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

5314 of 6725 relevant lines covered (79.02%)

200.29 hits per line

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

81.82
/common/common.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/common.hpp>
16
#include <common/error.hpp>
17

18
#include <cerrno>
19
#include <cstdlib>
20

21
namespace mender {
22
namespace common {
23

24
mender::common::expected::ExpectedLongLong StringToLongLong(const string &str, int base) {
322✔
25
        char *end;
26
        errno = 0;
322✔
27
        long long num = strtoll(str.c_str(), &end, base);
322✔
28
        if (errno != 0) {
322✔
29
                int int_error = errno;
×
30
                return expected::unexpected(mender::common::error::Error(
×
31
                        std::generic_category().default_error_condition(int_error), ""));
×
32
        }
33
        if (end != &*str.end()) {
322✔
34
                return expected::unexpected(mender::common::error::Error(
×
35
                        std::make_error_condition(errc::invalid_argument),
×
36
                        str + " had trailing non-numeric data"));
×
37
        }
38

39
        return num;
322✔
40
}
41

42
vector<string> SplitString(const string &str, const string &delim) {
94✔
43
        vector<string> ret;
94✔
44
        for (size_t begin = 0, end = str.find(delim);;) {
94✔
45
                if (end == string::npos) {
180✔
46
                        ret.push_back(string(str.begin() + begin, str.end()));
94✔
47
                        break;
94✔
48
                } else {
49
                        ret.push_back(string(str.begin() + begin, str.begin() + end));
86✔
50
                        begin = end + 1;
86✔
51
                        end = str.find(delim, begin);
86✔
52
                }
53
        }
54
        return ret;
94✔
55
}
56

57
string JoinStrings(const vector<string> &str, const string &delim) {
88✔
58
        string ret;
88✔
59
        auto s = str.begin();
88✔
60
        if (s == str.end()) {
88✔
61
                return ret;
4✔
62
        }
63
        ret += *s;
84✔
64
        s++;
84✔
65
        for (; s != str.end(); s++) {
463✔
66
                ret += delim;
379✔
67
                ret += *s;
379✔
68
        }
69
        return ret;
84✔
70
}
71

72
} // namespace common
73
} // namespace mender
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