17#include <openssl/evp.h>
18#include <openssl/conf.h>
20#if OPENSSL_API_LEVEL < 30000
21#include <openssl/engine.h>
23#include <openssl/provider.h>
42 {
static std::string _type(
"md5" );
return _type; }
45 {
static std::string _type(
"sha1" );
return _type; }
48 {
static std::string _type(
"sha224" );
return _type; }
51 {
static std::string _type(
"sha256" );
return _type; }
54 {
static std::string _type(
"sha384" );
return _type; }
57 {
static std::string _type(
"sha512" );
return _type; }
62 P(
const P&
p) =
delete;
73#if OPENSSL_API_LEVEL >= 30000
108 if(!openssl_digests_added)
110#if OPENSSL_API_LEVEL >= 30000
117 ERR <<
"Failed to load legacy openssl provider" << std::endl;
120 ERR <<
"Failed to load default openssl provider" << std::endl;
125# if OPENSSL_VERSION_NUMBER >= 0x10100000L
134 openssl_digests_added =
true;
139#if OPENSSL_API_LEVEL >= 30000
149#if OPENSSL_VERSION_NUMBER < 0x10100000L
162 ::memset(md_value, 0,
sizeof(md_value));
173#if OPENSSL_API_LEVEL >= 30000
190 _dp = std::move( other._dp );
199 if(
name.empty())
return false;
206 return _dp->maybeInit();
221 _dp->finalized =
true;
225 _dp->finalized =
false;
226 _dp->bytesHashed = 0;
233 if ( !
_dp->name.empty () )
234 d.create (
_dp->name );
246 return std::string();
248 std::vector<char>
resData (
vec.size()*2 + 1,
'\0' );
250 for(
unsigned i = 0;
i <
vec.size(); ++
i)
252 ::snprintf(
mdtxt+(
i*2), 3,
"%02hhx",
vec[
i]);
254 return std::string(
resData.data() );
257#ifdef __cpp_lib_string_view
259 template <
typename BArr>
262 for ( std::string::size_type
i = 0;
i <
str.length();
i+=2 )
264 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
265 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
266 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
275 bytes.back() = (bytes.back() << 4) | v;
282 ByteArray Digest::hexStringToByteArray(std::string_view
str)
284 return hexStrToBArr<ByteArray>( std::move(
str) );
287 UByteArray Digest::hexStringToUByteArray( std::string_view
str )
289 return hexStrToBArr<UByteArray>( std::move(
str) );
296 if(!
_dp->maybeInit())
303 _dp->finalized =
true;
305 r.reserve(
_dp->md_len);
306 for(
unsigned i = 0;
i <
_dp->md_len; ++
i)
307 r.push_back(
_dp->md_value[
i]);
318 if(!
_dp->maybeInit())
324 if(!
_dp->maybeInit())
331 _dp->bytesHashed += len;
356 return _dp->bytesHashed;
362 return std::string();
366 return std::string();
369 return std::string();
376 std::istringstream
is(
input );
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
Store and operate with byte count.
unsigned char md_value[EVP_MAX_MD_SIZE]
static bool openssl_digests_added
const P & operator=(const P &p)=delete
zypp::ByteCount bytesHashed
zypp::shared_ptr< EVP_MD_CTX > EvpDataPtr
P & operator=(P &&)=delete
Compute Message Digests (MD5, SHA1 etc)
static const std::string & md5()
md5
static const std::string & sha384()
sha384
std::string digest()
get hex string representation of the digest
static const std::string & sha512()
sha512
UByteArray digestVector()
get vector of unsigned char representation of the digest
static const std::string & sha1()
sha1
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
Digest clone() const
Returns a clone of the current Digest and returns it.
zypp::ByteCount bytesHashed() const
Returns the number of input bytes that have been added to the hash.
static const std::string & sha256()
sha256
const Digest & operator=(const Digest &d)=delete
static const std::string & sha224()
sha224
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
bool reset()
reset internal digest state
const std::string & name()
get the name of the current digest algorithm
bool create(const std::string &name)
initialize creation of a new message digest
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
zypp::UByteArray UByteArray
zypp::ByteArray ByteArray