libzypp  17.31.31
Digest.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
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);
52  Digest& operator=( Digest&& other);
53 
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
127 
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
UByteArray digestVector()
get vector of unsigned char representation of the digest
Definition: Digest.cc:291
static const std::string & sha256()
sha256
Definition: Digest.cc:50
static const std::string & sha1()
sha1
Definition: Digest.cc:44
std::string digest()
get hex string representation of the digest
Definition: Digest.cc:236
Compute Message Digests (MD5, SHA1 etc)
Definition: Digest.h:37
Store and operate with byte count.
Definition: ByteCount.h:30
String related utilities and Regular expression matching.
const std::string & name()
get the name of the current digest algorithm
Definition: Digest.cc:207
const Digest & operator=(const Digest &d)=delete
bool reset()
reset internal digest state
Definition: Digest.cc:212
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Definition: Digest.cc:241
std::unique_ptr< P > _dp
Definition: Digest.h:40
static const std::string & sha512()
sha512
Definition: Digest.cc:56
zypp::ByteCount bytesHashed() const
Returns the number of input bytes that have been added to the hash.
Definition: Digest.cc:352
bool create(const std::string &name)
initialize creation of a new message digest
Definition: Digest.cc:195
static const std::string & md5()
md5
Definition: Digest.cc:41
static const std::string & sha224()
sha224
Definition: Digest.cc:47
Digest clone() const
Returns a clone of the current Digest and returns it.
Definition: Digest.cc:228
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
Definition: Digest.cc:309
static const std::string & sha384()
sha384
Definition: Digest.cc:53