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/sha1hash.hpp" | ||
29 | |||
30 | namespace gate | ||
31 | { | ||
32 | namespace enc | ||
33 | { | ||
34 | |||
35 | 4 | Sha1Hash::Sha1Hash() | |
36 | 4 | : impl(gate_sha1_t()) | |
37 | { | ||
38 | 4 | this->reset(); | |
39 | 4 | } | |
40 | 4 | Sha1Hash::~Sha1Hash() | |
41 | { | ||
42 | 4 | } | |
43 | 7 | void Sha1Hash::reset() | |
44 | { | ||
45 | 7 | gate_sha1_init(&this->impl); | |
46 | 7 | } | |
47 | |||
48 | 3 | void Sha1Hash::update(void const* databuffer, gate_size_t databufferlength) | |
49 | { | ||
50 | 3 | gate_sha1_update(&this->impl, databuffer, (unsigned)databufferlength); | |
51 | 3 | } | |
52 | 4 | void Sha1Hash::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_sha1_update(&this->impl, buffer, (unsigned)returned); |
59 | } | ||
60 | 2 | } | |
61 | 2 | void Sha1Hash::update(String const& text) | |
62 | { | ||
63 | 2 | gate_sha1_update(&this->impl, text.c_str(), (unsigned)text.length()); | |
64 | 2 | } | |
65 | |||
66 | 6 | void Sha1Hash::computeResult(sha1_result_t& result) | |
67 | { | ||
68 | 6 | gate_sha1_finish(&this->impl, &result); | |
69 | 6 | } | |
70 | 6 | String Sha1Hash::computeResult() | |
71 | { | ||
72 | sha1_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 Sha1Hash::compute(Stream& stream) | |
78 | { | ||
79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Sha1Hash 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 Sha1Hash::compute(String const& text) | |
84 | { | ||
85 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Sha1Hash 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 Sha1Hash::compute(void const* databuffer, gate_size_t databufferlength) | |
90 | { | ||
91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Sha1Hash 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 | ✗ | Sha1HashBuilder::Sha1HashBuilder() | |
99 | { | ||
100 | ✗ | } | |
101 | |||
102 | ✗ | Sha1HashBuilder::~Sha1HashBuilder() noexcept | |
103 | { | ||
104 | ✗ | } | |
105 | |||
106 | ✗ | void Sha1HashBuilder::reset() | |
107 | { | ||
108 | ✗ | this->impl.reset(); | |
109 | ✗ | } | |
110 | |||
111 | ✗ | void Sha1HashBuilder::update(void const* data, size_t length) | |
112 | { | ||
113 | ✗ | this->impl.update(data, length); | |
114 | ✗ | } | |
115 | |||
116 | ✗ | Blob Sha1HashBuilder::computeHash() | |
117 | { | ||
118 | Sha1Hash::sha1_result_t result; | ||
119 | ✗ | this->impl.computeResult(result); | |
120 | ✗ | return Blob(&result.hash[0], sizeof(result.hash)); | |
121 | } | ||
122 | |||
123 | } // end of namespace enc | ||
124 | } // end of namespace gate | ||
125 |