Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | #include "gate/encode/md5hash.hpp" | ||
29 | |||
30 | namespace gate | ||
31 | { | ||
32 | namespace enc | ||
33 | { | ||
34 | |||
35 | 4 | Md5Hash::Md5Hash() | |
36 | 4 | : impl(gate_md5_t()) | |
37 | { | ||
38 | 4 | this->reset(); | |
39 | 4 | } | |
40 | 4 | Md5Hash::~Md5Hash() | |
41 | { | ||
42 | 4 | } | |
43 | 7 | void Md5Hash::reset() | |
44 | { | ||
45 | 7 | gate_md5_init(&this->impl); | |
46 | 7 | } | |
47 | |||
48 | 3 | void Md5Hash::update(void const* databuffer, gate_size_t databufferlength) | |
49 | { | ||
50 | 3 | gate_md5_update(&this->impl, databuffer, (unsigned)databufferlength); | |
51 | 3 | } | |
52 | 4 | void Md5Hash::update(Stream& stream) | |
53 | { | ||
54 | char buffer[GATE_MAX_COPYBUFFER_LENGTH]; | ||
55 | gate_size_t returned; | ||
56 |
3/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | while (0 != (returned = stream.read(buffer, sizeof(buffer)))) |
57 | { | ||
58 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_md5_update(&this->impl, buffer, (unsigned)returned); |
59 | } | ||
60 | 2 | } | |
61 | 2 | void Md5Hash::update(String const& text) | |
62 | { | ||
63 | 2 | gate_md5_update(&this->impl, text.c_str(), (unsigned)text.length()); | |
64 | 2 | } | |
65 | |||
66 | 6 | void Md5Hash::computeResult(md5_result_t& result) | |
67 | { | ||
68 | 6 | gate_md5_finish(&this->impl, &result); | |
69 | 6 | } | |
70 | 6 | String Md5Hash::computeResult() | |
71 | { | ||
72 | md5_result_t result; | ||
73 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | this->computeResult(result); |
74 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | return String((char const*)&result.hash[0], sizeof(result.hash)); |
75 | } | ||
76 | |||
77 | 1 | String Md5Hash::compute(Stream& stream) | |
78 | { | ||
79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Md5Hash hash; |
80 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | hash.update(stream); |
81 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return hash.computeResult(); |
82 | } | ||
83 | 1 | String Md5Hash::compute(String const& text) | |
84 | { | ||
85 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Md5Hash hash; |
86 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | hash.update(text); |
87 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return hash.computeResult(); |
88 | } | ||
89 | 1 | String Md5Hash::compute(void const* databuffer, gate_size_t databufferlength) | |
90 | { | ||
91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Md5Hash hash; |
92 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | hash.update(databuffer, databufferlength); |
93 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return hash.computeResult(); |
94 | } | ||
95 | |||
96 | |||
97 | |||
98 | ✗ | Md5HashBuilder::Md5HashBuilder() | |
99 | { | ||
100 | ✗ | } | |
101 | ✗ | Md5HashBuilder::~Md5HashBuilder() noexcept | |
102 | { | ||
103 | ✗ | } | |
104 | |||
105 | ✗ | void Md5HashBuilder::reset() | |
106 | { | ||
107 | ✗ | this->impl.reset(); | |
108 | ✗ | } | |
109 | ✗ | void Md5HashBuilder::update(void const* data, size_t length) | |
110 | { | ||
111 | ✗ | this->impl.update(data, length); | |
112 | ✗ | } | |
113 | ✗ | Blob Md5HashBuilder::computeHash() | |
114 | { | ||
115 | Md5Hash::md5_result_t result; | ||
116 | ✗ | this->impl.computeResult(result); | |
117 | ✗ | return Blob(&result.hash[0], sizeof(result.hash)); | |
118 | } | ||
119 | |||
120 | |||
121 | } // end of namespace enc | ||
122 | } // end of namespace gate | ||
123 |