libzypp  17.31.31
zypp::Digest Class Reference

Compute Message Digests (MD5, SHA1 etc) More...

#include <Digest.h>

Classes

class  P
 

Public Member Functions

 Digest (Digest &&other)
 
Digestoperator= (Digest &&other)
 
 Digest ()
 
 ~Digest ()
 
bool create (const std::string &name)
 initialize creation of a new message digest More...
 
const std::string & name ()
 get the name of the current digest algorithm More...
 
bool update (const char *bytes, size_t len)
 feed data into digest computation algorithm More...
 
bool update (std::istream &is, size_t bufsize=4096)
 feed data into digest computation algorithm More...
 
zypp::ByteCount bytesHashed () const
 Returns the number of input bytes that have been added to the hash. More...
 
std::string digest ()
 get hex string representation of the digest More...
 
UByteArray digestVector ()
 get vector of unsigned char representation of the digest More...
 
bool reset ()
 reset internal digest state More...
 
Digest clone () const
 Returns a clone of the current Digest and returns it. More...
 

Static Public Member Functions

static std::string digestVectorToString (const UByteArray &vec)
 get hex string representation of the digest vector given as parameter More...
 
static std::string digest (const std::string &name, std::istream &is, size_t bufsize=4096)
 compute digest of a stream. More...
 
static std::string digest (const std::string &name, const std::string &input, size_t bufsize=4096)
 
Well known digest algorithm names.
static const std::string & md5 ()
 md5 More...
 
static const std::string & sha1 ()
 sha1 More...
 
static const std::string & sha224 ()
 sha224 More...
 
static const std::string & sha256 ()
 sha256 More...
 
static const std::string & sha384 ()
 sha384 More...
 
static const std::string & sha512 ()
 sha512 More...
 

Private Member Functions

 Digest (const Digest &d)=delete
 
const Digestoperator= (const Digest &d)=delete
 

Private Attributes

std::unique_ptr< P_dp
 

Detailed Description

Compute Message Digests (MD5, SHA1 etc)

The computation works by initializing the algorithm using create(). This will construct an internal state. successive calls to update() deliver the data for which the digest is to be computed. After all data has been deliverd, a call to digest() finalizes the computation and returns the result

Definition at line 37 of file Digest.h.

Constructor & Destructor Documentation

◆ Digest() [1/3]

zypp::Digest::Digest ( const Digest d)
privatedelete

◆ Digest() [2/3]

zypp::Digest::Digest ( Digest &&  other)

Definition at line 182 of file Digest.cc.

◆ Digest() [3/3]

zypp::Digest::Digest ( )

Definition at line 178 of file Digest.cc.

◆ ~Digest()

zypp::Digest::~Digest ( )

Definition at line 192 of file Digest.cc.

Member Function Documentation

◆ operator=() [1/2]

const Digest& zypp::Digest::operator= ( const Digest d)
privatedelete

◆ operator=() [2/2]

Digest & zypp::Digest::operator= ( Digest &&  other)

Definition at line 186 of file Digest.cc.

◆ md5()

const std::string & zypp::Digest::md5 ( )
static

md5

Definition at line 41 of file Digest.cc.

◆ sha1()

const std::string & zypp::Digest::sha1 ( )
static

sha1

Definition at line 44 of file Digest.cc.

◆ sha224()

const std::string & zypp::Digest::sha224 ( )
static

sha224

Definition at line 47 of file Digest.cc.

◆ sha256()

const std::string & zypp::Digest::sha256 ( )
static

sha256

Definition at line 50 of file Digest.cc.

◆ sha384()

const std::string & zypp::Digest::sha384 ( )
static

sha384

Definition at line 53 of file Digest.cc.

◆ sha512()

const std::string & zypp::Digest::sha512 ( )
static

sha512

Definition at line 56 of file Digest.cc.

◆ create()

bool zypp::Digest::create ( const std::string &  name)

initialize creation of a new message digest

Since openssl is used as backend you may use anything that openssl supports (see man 1 dgst). Common examples are md5 or sha1. sha1 should be preferred when creating digests to verify the authenticity of something.

successive calls to this funcion will destroy the internal state and reinit from scratch

Parameters
namename of the message digest algorithm.
Returns
whether an error occured

Definition at line 195 of file Digest.cc.

◆ name()

const std::string & zypp::Digest::name ( )

get the name of the current digest algorithm

Definition at line 207 of file Digest.cc.

◆ update() [1/2]

bool zypp::Digest::update ( const char *  bytes,
size_t  len 
)

feed data into digest computation algorithm

Parameters
bytes
len
Returns
whether an error occured

Definition at line 309 of file Digest.cc.

◆ update() [2/2]

bool zypp::Digest::update ( std::istream &  is,
size_t  bufsize = 4096 
)

feed data into digest computation algorithm

Parameters
is
bufsize
Returns
whether an error occured

Definition at line 333 of file Digest.cc.

◆ bytesHashed()

ByteCount zypp::Digest::bytesHashed ( ) const

Returns the number of input bytes that have been added to the hash.

Definition at line 352 of file Digest.cc.

◆ digest() [1/3]

std::string zypp::Digest::digest ( )

get hex string representation of the digest

this function will finalize the digest computation. calls to update after this function will start from scratch

Returns
hex string representation of the digest

Definition at line 236 of file Digest.cc.

◆ digestVectorToString()

std::string zypp::Digest::digestVectorToString ( const UByteArray vec)
static

get hex string representation of the digest vector given as parameter

Returns
hex string representation of the digest

Definition at line 241 of file Digest.cc.

◆ digestVector()

UByteArray zypp::Digest::digestVector ( )

get vector of unsigned char representation of the digest

this function will finalize the digest computation. calls to update after this function will start from scratch

Returns
vector representation of the digest

Definition at line 291 of file Digest.cc.

◆ reset()

bool zypp::Digest::reset ( )

reset internal digest state

this function is equivalent to calling create() with an unchanged name, but it may be implemented in a more efficient way.

Definition at line 212 of file Digest.cc.

◆ clone()

Digest zypp::Digest::clone ( ) const

Returns a clone of the current Digest and returns it.

This is the same as manually creating a Digest with the same name ( so no checksum calculation state is copied )

Definition at line 228 of file Digest.cc.

◆ digest() [2/3]

std::string zypp::Digest::digest ( const std::string &  name,
std::istream &  is,
size_t  bufsize = 4096 
)
static

compute digest of a stream.

convenience function

calls create, update and digest in one function. The data for the computation is read from the stream

Parameters
namename of the digest algorithm,
See also
create
Parameters
isan input stream to get the data from
bufsizesize of the buffer used for update(). Be careful, this is on the stack.
Returns
the digest or empty on error

Definition at line 357 of file Digest.cc.

◆ digest() [3/3]

std::string zypp::Digest::digest ( const std::string &  name,
const std::string &  input,
size_t  bufsize = 4096 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 372 of file Digest.cc.

Member Data Documentation

◆ _dp

std::unique_ptr<P> zypp::Digest::_dp
private

Definition at line 40 of file Digest.h.


The documentation for this class was generated from the following files: