libxcks  0.1.0.1
checksum.hpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
24 #ifndef INC_CHECKSUM_HPP_BA2B9BF9_F9EA_43FB_8766_A19F518D1864
25 #define INC_CHECKSUM_HPP_BA2B9BF9_F9EA_43FB_8766_A19F518D1864
26 
27 //---------------------------------------------------------------------------
28 // #include <string> // included in libxcks/types.hpp
29 #include <cstdint>
30 
31 #include "libxcks/export.hpp"
32 #include "libxcks/types.hpp"
33 //---------------------------------------------------------------------------
34 
35 
36 namespace libxcks
37 {
53 class LIBXCKS_SO_EXPORT Checksum
54 {
55  public:
59  virtual ~Checksum() {}
60 
61 
65  virtual void reset() = 0;
66 
74  virtual std::string toString(const bool hexInUpperCase = false) const = 0;
75 
85  virtual uint8_t* getValue(uint8_t* buffer) const = 0;
86 
94  virtual size_t getSize() const = 0;
95 
102  virtual void update(const uint8_t* buf, size_t len) = 0;
103 
109  virtual std::string getName() const = 0;
110 
116  virtual ArrayString getAltNames() const
117  {
118  return ArrayString();
119  }
120 
130  virtual ChecksumAlgoId getID() const = 0;
131 
138  {
139  return ArrayString();
140  }
141 };
142 //---------------------------------------------------------------------------
143 } // namespace libxcks
144 //---------------------------------------------------------------------------
145 
146 #endif // INC_CHECKSUM_HPP_BA2B9BF9_F9EA_43FB_8766_A19F518D1864
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
virtual ~Checksum()
Destructor.
Definition: checksum.hpp:59
virtual std::string getName() const =0
Returns the name of the checksum or the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative name(s) of the checksum or the hash algorithm.
Definition: checksum.hpp:137
virtual ArrayString getAltNames() const
Returns the alternative name(s) of the checksum or the hash algorithm.
Definition: checksum.hpp:116
virtual ChecksumAlgoId getID() const =0
Returns an unique identifier for the checksum or the hash algorithm.
virtual std::string toString(const bool hexInUpperCase=false) const =0
Returns the checksum value in a string.
virtual size_t getSize() const =0
Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) metho...
virtual void reset()=0
Resets the checksum to initial value.
virtual void update(const uint8_t *buf, size_t len)=0
Updates the checksum with specified array of bytes.
virtual uint8_t * getValue(uint8_t *buffer) const =0
Returns the checksum value in the first bytes of the given address.
OS dependent exports defines.
Common types for libxcks.
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44