libzypp 17.37.17
Digest.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
14
15#ifndef ZYPP_CORE_DIGEST_H
16#define ZYPP_CORE_DIGEST_H
17
18#include <string>
19#include <iosfwd>
20#include <memory>
21#include <optional>
22
23#include <zypp-core/Pathname.h>
24#include <zypp-core/ByteArray.h>
25#include <zypp-core/ByteCount.h>
26
27namespace zypp {
28
37 class Digest
38 {
39 private:
40 class P;
41 std::unique_ptr<P> _dp;
42
43 // disabled
44 Digest(const Digest& d) = delete;
45 // disabled
46 const Digest& operator=(const Digest& d) = delete;
47
48 public:
49
50 // moving is fine
51 Digest(Digest&& other) noexcept;
52 Digest& operator=( Digest&& other) noexcept;
53
56
57 static const std::string & md5();
59 static const std::string & sha1();
61 static const std::string & sha224();
63 static const std::string & sha256();
65 static const std::string & sha384();
67 static const std::string & sha512();
69
70 public:
71 Digest();
72 ~Digest();
73
87 bool create(const std::string& name);
88
90 const std::string& name();
91
97 bool update(const char* bytes, size_t len);
98
104 bool update(std::istream& is, size_t bufsize = 4096);
105
110
118 std::string digest();
119
124 static std::string digestVectorToString ( const UByteArray &vec );
125
126#ifdef __cpp_lib_string_view
131 static ByteArray hexStringToByteArray ( std::string_view str );
132 static UByteArray hexStringToUByteArray ( std::string_view str );
133#endif
134
143
149 bool reset();
150
156 Digest clone() const;
157
168 static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096);
169
171 static std::string digest( const std::string & name, const std::string & input, size_t bufsize = 4096 );
172 };
173
174} // namespace zypp
175
176#endif
Store and operate with byte count.
Definition ByteCount.h:32
static const std::string & md5()
md5
Definition Digest.cc:42
static const std::string & sha384()
sha384
Definition Digest.cc:54
std::string digest()
get hex string representation of the digest
Definition Digest.cc:239
static const std::string & sha512()
sha512
Definition Digest.cc:57
UByteArray digestVector()
get vector of unsigned char representation of the digest
Definition Digest.cc:270
static const std::string & sha1()
sha1
Definition Digest.cc:45
Digest(const Digest &d)=delete
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
Definition Digest.cc:288
Digest clone() const
Returns a clone of the current Digest and returns it.
Definition Digest.cc:231
zypp::ByteCount bytesHashed() const
Returns the number of input bytes that have been added to the hash.
Definition Digest.cc:331
std::unique_ptr< P > _dp
Definition Digest.h:41
static const std::string & sha256()
sha256
Definition Digest.cc:51
const Digest & operator=(const Digest &d)=delete
static const std::string & sha224()
sha224
Definition Digest.cc:48
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Definition Digest.cc:244
bool reset()
reset internal digest state
Definition Digest.cc:215
const std::string & name()
get the name of the current digest algorithm
Definition Digest.cc:210
bool create(const std::string &name)
initialize creation of a new message digest
Definition Digest.cc:198
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.