libzypp 17.37.10

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
27 namespace 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
109 zypp::ByteCount bytesHashed () const;
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
142 UByteArray digestVector();
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
zypp::ByteArray
Definition ByteArray.h:19
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::Digest::P
Definition Digest.cc:62
zypp::Digest::md5
static const std::string & md5()
md5
Definition Digest.cc:42
zypp::Digest::sha384
static const std::string & sha384()
sha384
Definition Digest.cc:54
zypp::Digest::digest
std::string digest()
get hex string representation of the digest
Definition Digest.cc:239
zypp::Digest::~Digest
~Digest()
Definition Digest.cc:195
zypp::Digest::Digest
Digest()
Definition Digest.cc:181
zypp::Digest::sha512
static const std::string & sha512()
sha512
Definition Digest.cc:57
zypp::Digest::digestVector
UByteArray digestVector()
get vector of unsigned char representation of the digest
Definition Digest.cc:270
zypp::Digest::sha1
static const std::string & sha1()
sha1
Definition Digest.cc:45
zypp::Digest::Digest
Digest(const Digest &d)=delete
zypp::Digest::update
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
Definition Digest.cc:288
zypp::Digest::clone
Digest clone() const
Returns a clone of the current Digest and returns it.
Definition Digest.cc:231
zypp::Digest::bytesHashed
zypp::ByteCount bytesHashed() const
Returns the number of input bytes that have been added to the hash.
Definition Digest.cc:331
zypp::Digest::_dp
std::unique_ptr< P > _dp
Definition Digest.h:41
zypp::Digest::sha256
static const std::string & sha256()
sha256
Definition Digest.cc:51
zypp::Digest::operator=
const Digest & operator=(const Digest &d)=delete
zypp::Digest::sha224
static const std::string & sha224()
sha224
Definition Digest.cc:48
zypp::Digest::digestVectorToString
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Definition Digest.cc:244
zypp::Digest::reset
bool reset()
reset internal digest state
Definition Digest.cc:215
zypp::Digest::name
const std::string & name()
get the name of the current digest algorithm
Definition Digest.cc:210
zypp::Digest::create
bool create(const std::string &name)
initialize creation of a new message digest
Definition Digest.cc:198
zypp::UByteArray
Definition ByteArray.h:46
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
ByteArray.h
ByteCount.h
Pathname.h