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