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

mendersoftware / mender / 1307057183

27 May 2024 12:03PM UTC coverage: 75.487% (-0.01%) from 75.497%
1307057183

push

gitlab-ci

lluiscampos
chore(artifact/sha): Move platform agnostic code out

Signed-off-by: Lluis Campos <lluis.campos@northern.tech>

12 of 22 new or added lines in 1 file covered. (54.55%)

3 existing lines in 2 files now uncovered.

7058 of 9350 relevant lines covered (75.49%)

11658.21 hits per line

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

54.55
/src/artifact/sha/sha.cpp
1
// Copyright 2024 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 <cstdint>
16
#include <string>
17
#include <ctime>
18
#include <iomanip>
19
#include <vector>
20
#include <sstream>
21
#include <algorithm>
22

23
#include <openssl/evp.h>
24
#include <artifact/sha/sha.hpp>
25

26
#include <common/common.hpp>
27
#include <common/io.hpp>
28

29

30
namespace mender {
31
namespace sha {
32

33
namespace log = mender::common::log;
34
namespace io = mender::common::io;
35

36
const ErrorCategoryClass ErrorCategory = ErrorCategoryClass();
37

NEW
38
const char *ErrorCategoryClass::name() const noexcept {
×
NEW
39
        return "ShaSumErrorCategory";
×
40
}
41

NEW
42
string ErrorCategoryClass::message(int code) const {
×
NEW
43
        switch (code) {
×
44
        case NoError:
NEW
45
                return "Success";
×
46
        case InitializationError:
NEW
47
                return "Initialization error";
×
48
        case ShasumCreationError:
NEW
49
                return "Shasum creation error";
×
50
        case ShasumMismatchError:
NEW
51
                return "Shasum mismatch error";
×
52
        default:
NEW
53
                return "Unknown";
×
54
        }
55
}
56

57
error::Error MakeError(ErrorCode code, const string &msg) {
3✔
58
        return error::Error(error_condition(code, ErrorCategory), msg);
3✔
59
}
60

61

62
Reader::Reader(io::Reader &reader) :
164✔
63
        Reader::Reader {reader, ""} {
328✔
64
}
164✔
65

66
ExpectedSHA Shasum(const vector<uint8_t> &data) {
12✔
67
        string in {data.begin(), data.end()};
12✔
68

69
        io::StringReader is {in};
24✔
70

71
        Reader r {is};
24✔
72

73
        auto discard_writer = io::Discard {};
74

75
        auto err = io::Copy(discard_writer, r);
12✔
76
        if (err != error::NoError) {
12✔
NEW
77
                return expected::unexpected(err);
×
78
        }
79

80
        return r.ShaSum();
12✔
81
}
82

83
} // namespace sha
84
} // 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