libzypp  17.31.22
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 <vector>
21 
22 #include <zypp-core/Pathname.h>
23 #include <zypp-core/ByteArray.h>
24 #include <zypp-core/ByteCount.h>
25 
26 namespace zypp {
27 
36  class Digest
37  {
38  private:
39  class P;
40  P* _dp;
41 
42  // disabled
43  Digest(const Digest& d);
44  // disabled
45  const Digest& operator=(const Digest& d);
46 
47  public:
51  static const std::string & md5();
53  static const std::string & sha1();
55  static const std::string & sha224();
57  static const std::string & sha256();
59  static const std::string & sha384();
61  static const std::string & sha512();
63 
64  public:
65  Digest();
66  ~Digest();
67 
81  bool create(const std::string& name);
82 
84  const std::string& name();
85 
91  bool update(const char* bytes, size_t len);
92 
98  bool update(std::istream& is, size_t bufsize = 4096);
99 
103  zypp::ByteCount bytesHashed () const;
104 
112  std::string digest();
113 
118  static std::string digestVectorToString ( const UByteArray &vec );
119 
120 #ifdef __cpp_lib_string_view
121 
125  static ByteArray hexStringToByteArray ( std::string_view str );
126  static UByteArray hexStringToUByteArray ( std::string_view str );
127 #endif
128 
137 
143  bool reset();
144 
155  static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096);
156 
158  static std::string digest( const std::string & name, const std::string & input, size_t bufsize = 4096 );
159  };
160 
161 } // namespace zypp
162 
163 #endif
UByteArray digestVector()
get vector of unsigned char representation of the digest
Definition: Digest.cc:234
static const std::string & sha256()
sha256
Definition: Digest.cc:41
static const std::string & sha1()
sha1
Definition: Digest.cc:35
std::string digest()
get hex string representation of the digest
Definition: Digest.cc:179
Compute Message Digests (MD5, SHA1 etc)
Definition: Digest.h:36
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:158
bool reset()
reset internal digest state
Definition: Digest.cc:163
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Definition: Digest.cc:184
static const std::string & sha512()
sha512
Definition: Digest.cc:47
const Digest & operator=(const Digest &d)
zypp::ByteCount bytesHashed() const
Returns the number of input bytes that have been added to the hash.
Definition: Digest.cc:295
bool create(const std::string &name)
initialize creation of a new message digest
Definition: Digest.cc:146
static const std::string & md5()
md5
Definition: Digest.cc:32
P * _dp
Definition: Digest.h:39
static const std::string & sha224()
sha224
Definition: Digest.cc:38
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:252
static const std::string & sha384()
sha384
Definition: Digest.cc:44