ewmscp  ..
Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
checksum::sslSum Class Reference

class to calculate checksums via openssl. More...

#include <sslCheckSum.h>

Inheritance diagram for checksum::sslSum:
[legend]
Collaboration diagram for checksum::sslSum:
[legend]

Public Member Functions

 sslSum (const std::string &name)
 
virtual ~sslSum ()
 
void update (void *data, size_t size) override
 proces size bytes in the block at data More...
 
void update (size_t size) override
 proces size many zero bytes More...
 
void finish () override
 finish calculation ad write to result More...
 
- Public Member Functions inherited from checksum::base
virtual ~base ()=default
 
virtual bool parallelizable () const
 
const std::string & getName () const
 
const std::string & getResult () const
 
void setExpectedResult (const std::string &expectedResult)
 
const std::string & getExpectedResult () const
 
bool checkExpectation () const
 

Static Private Member Functions

static void createFactoryCallback (const OBJ_NAME *obj, void *)
 
static bool createFactories ()
 

Private Attributes

decltype(EVP_MD_CTX_create()) ctx
 
decltype(EVP_md5()) mdType
 

Static Private Attributes

static bool factoryInitStateDummy
 

Additional Inherited Members

- Static Public Member Functions inherited from checksum::base
static factoryClassnewFactory (const std::string &aName)
 
template<class T >
static void addAllowedNamesToOption (T &option)
 
- Protected Member Functions inherited from checksum::base
 base (const std::string &aName)
 
- Static Protected Member Functions inherited from checksum::base
static std::map< std::string, factoryClass * > & getFactoryMap ()
 
- Protected Attributes inherited from checksum::base
const std::string & name
 
std::string result
 
std::string expected
 

Detailed Description

class to calculate checksums via openssl.

Definition at line 11 of file sslCheckSum.h.

Constructor & Destructor Documentation

◆ sslSum()

checksum::sslSum::sslSum ( const std::string &  name)

Definition at line 31 of file sslCheckSum.cpp.

31  : base(aName) {
32  ctx = EVP_MD_CTX_create();
33 
34  mdType = EVP_get_digestbyname(name.c_str());
35  if (mdType == nullptr) {
36  throw std::runtime_error("got no ssl digest named " + name);
37  }
38  EVP_MD_CTX_init(ctx);
39  EVP_DigestInit_ex(ctx, mdType, nullptr);
40  }

References ctx, mdType, and checksum::base::name.

◆ ~sslSum()

checksum::sslSum::~sslSum ( )
virtual

Definition at line 41 of file sslCheckSum.cpp.

41  {
42  EVP_MD_CTX_destroy(ctx);
43  }

References ctx.

Member Function Documentation

◆ createFactories()

bool checksum::sslSum::createFactories ( )
staticprivate

Definition at line 24 of file sslCheckSum.cpp.

24  {
25  OpenSSL_add_all_digests();
26  OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, createFactoryCallback, nullptr);
27  return true;
28  }

References createFactoryCallback().

Here is the call graph for this function:

◆ createFactoryCallback()

void checksum::sslSum::createFactoryCallback ( const OBJ_NAME *  obj,
void *   
)
staticprivate

Definition at line 10 of file sslCheckSum.cpp.

10  {
11  std::string name(obj->name);
12  for (const auto& unwanted : {
13  "With", "with", "Encryption", "ssl2-", "ssl3-", "160"
14  }) {
15  if (name.find(unwanted) != decltype(name)::npos) {
16  return;
17  }
18  }
19  if (name.front() >= 'A' && name.front() <= 'Z') {
20  return;
21  }
22  new base::factoryTemplate<sslSum>(name);
23  }

References checksum::base::name.

Referenced by createFactories().

Here is the caller graph for this function:

◆ finish()

void checksum::sslSum::finish ( )
overridevirtual

finish calculation ad write to result

Implements checksum::base.

Definition at line 57 of file sslCheckSum.cpp.

57  {
58  std::vector<unsigned char> md(EVP_MD_size(mdType));
59  EVP_DigestFinal_ex(ctx, md.data(), nullptr);
60  std::ostringstream hashBuffer;
61 
62  for (auto c : md) {
63  hashBuffer << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(c);
64  }
65 
66  result = hashBuffer.str();
67  }

References ctx, mdType, and checksum::base::result.

◆ update() [1/2]

void checksum::sslSum::update ( size_t  size)
overridevirtual

proces size many zero bytes

Implements checksum::base.

Definition at line 48 of file sslCheckSum.cpp.

48  { // case for block of zeroes
49  for (size_t bytes_done = 0; bytes_done < size;) {
50  auto missing = size - bytes_done;
51  auto bytes = std::min(missing, block::nullBufferSize());
52  EVP_DigestUpdate(ctx, block::nullBuffer(), bytes);
53  bytes_done += bytes;
54  }
55  }

References ctx, block::nullBuffer(), and block::nullBufferSize().

Here is the call graph for this function:

◆ update() [2/2]

void checksum::sslSum::update ( void *  data,
size_t  size 
)
overridevirtual

proces size bytes in the block at data

Implements checksum::base.

Definition at line 45 of file sslCheckSum.cpp.

45  {
46  EVP_DigestUpdate(ctx, data, size);
47  }

References ctx.

Member Data Documentation

◆ ctx

decltype(EVP_MD_CTX_create()) checksum::sslSum::ctx
private

Definition at line 16 of file sslCheckSum.h.

Referenced by finish(), sslSum(), update(), and ~sslSum().

◆ factoryInitStateDummy

bool checksum::sslSum::factoryInitStateDummy
staticprivate

Definition at line 15 of file sslCheckSum.h.

◆ mdType

decltype(EVP_md5()) checksum::sslSum::mdType
private

Definition at line 17 of file sslCheckSum.h.

Referenced by finish(), and sslSum().


The documentation for this class was generated from the following files:
block::nullBuffer
static const void * nullBuffer()
Definition: block.cpp:37
checksum::base::name
const std::string & name
Definition: checksumBase.h:37
checksum::base::base
base(const std::string &aName)
Definition: checksumBase.h:40
checksum::sslSum::ctx
decltype(EVP_MD_CTX_create()) ctx
Definition: sslCheckSum.h:16
checksum::sslSum::createFactoryCallback
static void createFactoryCallback(const OBJ_NAME *obj, void *)
Definition: sslCheckSum.cpp:10
block::nullBufferSize
static size_t nullBufferSize()
Definition: block.cpp:34
checksum::sslSum::mdType
decltype(EVP_md5()) mdType
Definition: sslCheckSum.h:17
checksum::base::result
std::string result
Definition: checksumBase.h:38