27 #include <boost/locale.hpp>
55 using namespace boost::locale;
90 ChecksumEntry(FnctGetChecksum* getChecksum,
const std::string& name,
92 const std::string& description);
122 ChecksumFactory::ChecksumEntry::ChecksumEntry(FnctGetChecksum* getChecksum,
123 const std::string& name,
125 const std::string& description) :
126 fnctGetChecksum(getChecksum), name(name), altNames(alternativeNames),
129 if (getChecksum !=
nullptr)
134 const size_t size = c->
getSize();
135 uint8_t* buf =
new uint8_t[size];
136 memset(buf, 0, size);
157 this->name = source.
name;
159 this->descr = source.
descr;
173 ChecksumFactory::ChecksumEntries ChecksumFactory::checksumAlgorithms;
234 checksumAlgorithms.emplace(Keccak224::getIdentifier(),
235 ChecksumEntry(Keccak224::getNewInstance, Keccak224::getHashName(),
236 Keccak224::getAlternativeNames(), translate(
"Keccak224 cryptographic hash function").str(
libxcks_domain)));
237 checksumAlgorithms.emplace(Keccak256::getIdentifier(),
238 ChecksumEntry(Keccak256::getNewInstance, Keccak256::getHashName(),
239 Keccak256::getAlternativeNames(), translate(
"Keccak256 cryptographic hash function").str(
libxcks_domain)));
240 checksumAlgorithms.emplace(Keccak384::getIdentifier(),
241 ChecksumEntry(Keccak384::getNewInstance, Keccak384::getHashName(),
242 Keccak384::getAlternativeNames(), translate(
"Keccak384 cryptographic hash function").str(
libxcks_domain)));
243 checksumAlgorithms.emplace(Keccak512::getIdentifier(),
244 ChecksumEntry(Keccak512::getNewInstance, Keccak512::getHashName(),
245 Keccak512::getAlternativeNames(), translate(
"Keccak512 cryptographic hash function").str(
libxcks_domain)));
265 checksumAlgorithms.clear();
285 return checksumAlgorithms[id].fnctGetChecksum();
307 const bool lookInAltNames)
311 return checksumAlgorithms[id].fnctGetChecksum();
330 return checksumAlgorithms[id].nullValue;
349 const bool lookInAltNames)
353 return checksumAlgorithms[id].nullValue;
371 return checksumAlgorithms[id].nullValue.getSize();
392 return checksumAlgorithms[id].nullValue.getSize();
411 const ChecksumEntries& ca = checksumAlgorithms;
412 ChecksumEntries::const_iterator it = ca.find(
id);
414 return (it != ca.end());
465 res.reserve(checksumAlgorithms.size());
467 const ChecksumEntries& ca = checksumAlgorithms;
468 for (ChecksumEntries::const_iterator it = ca.begin(); it != ca.end(); it++)
469 res.push_back(it->first);
484 res.reserve(checksumAlgorithms.size());
486 const ChecksumEntries& ca = checksumAlgorithms;
487 for (ChecksumEntries::const_iterator it = ca.begin(); it != ca.end(); it++)
488 res.emplace_back(it->second.name);
502 return checksumAlgorithms.size();
519 const bool lookInAltNames)
523 const ChecksumEntries& ca = checksumAlgorithms;
524 ChecksumEntries::const_iterator it = ca.begin();
525 while (!found && it != ca.end())
527 if (it->second.name == name)
532 else if (lookInAltNames)
535 size_t s = altNames.size();
537 while (!found && i < s)
539 if (altNames[i] == name)
570 const bool lookInAltNames)
574 const ChecksumEntries& ca = checksumAlgorithms;
575 ChecksumEntries::const_iterator it = ca.begin();
576 while (!found && it != ca.end())
583 else if (lookInAltNames)
586 size_t s = altNames.size();
588 while (!found && i < s)
621 name = checksumAlgorithms[id].name;
673 altNames = checksumAlgorithms[id].altNames;
675 altNames.emplace(altNames.begin(), checksumAlgorithms[
id].name);
704 const std::string& name,
705 const bool nameCouldBeAlt,
729 return checksumAlgorithms[id].descr;
748 const bool lookInAltNames)
752 return checksumAlgorithms[id].descr;
Checksum *() FnctGetChecksum()
Pointer to a function which returns a pointer on a new instance of the Checksum class.
Classes for enumerate and create all the checksums' algorithms that the application knows.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the checksum algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the CRC32 checksum algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getChecksumName()
Returns the name of the checksum algorithm.
static std::string getChecksumName()
Returns the name of the checksum algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static ArrayString getAlternativeNames()
Returns the alternative names of the CRC64 checksum algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the checksum algorithm.
Represents an entry of the checksum or hash algorithms that the application knows.
void clone(const ChecksumEntry &source)
Clones the source instance in this instance.
ArrayString altNames
Alternative name(s) of the checksum or hash algorithm.
FnctGetChecksum * fnctGetChecksum
Pointer on a function that gives a pointer on a new instance of the Checksum class.
ChecksumValue nullValue
The null value of the the checksum or hash.
std::string descr
Description of the checksum or hash algorithm.
std::string name
Name of the checksum or hash algorithm.
ChecksumEntry()
Default constructor.
ChecksumEntry & operator=(const ChecksumEntry &source)
Assignment operator.
ChecksumEntry(const ChecksumEntry &source)
Copy constructor.
static bool existsNoCase(const std::string &name, const bool lookInAltNames=true)
Returns true if the given name of the checksum or hash algorithm exists with no case comparison.
static ArrayString getAlgorithmsNames()
Returns all the names of the available checksum or hash algorithms.
static ArrayChecksumAlgoId getAlgorithmsIds()
Returns all the identifiers of the available checksum or hash algorithms.
static ChecksumValue getNullValue(const ChecksumAlgoId id)
Gives null value of the specified checksum or hash identifier.
static size_t getSize(const ChecksumAlgoId id)
Gets the size in bytes of the specified checksum or hash identifier.
static bool getAlgorithmAltNames(ArrayString &altNames, const ChecksumAlgoId id, const bool giveName=false)
Gets the alternatives names of a checksum or hash algorithm from its identifier.
static Checksum * getNewInstance(const ChecksumAlgoId id)
Gives a pointer on a new instance of the specified checksum or hash identifier.
static bool getAlgorithmId(ChecksumAlgoId &id, const std::string &name, const bool lookInAltNames=true)
Gets the identifier of a checksum or hash algorithm from its name.
static void cleanUp()
Cleans-up the static members of the class.
static int getAlgorithmsCount()
Returns the number of available checksum or hash algorithms.
static bool getAlgorithmName(std::string &name, const ChecksumAlgoId id)
Gets the name of a checksum or hash algorithm from its identifier.
static std::string getAlgorithmDescription(const ChecksumAlgoId id)
Returns the description of a checksum or hash algorithm from its identifier.
static bool getAlgorithmIdNoCase(ChecksumAlgoId &id, const std::string &name, const bool lookInAltNames=true)
Gets the identifier of a checksum or hash algorithm from its name with no case comparison.
static bool exists(const ChecksumAlgoId id)
Returns true if the given identifier of the checksum or hash algorithm exists.
static void initialise()
Initializes the static members of the class.
Stores the value of a checksum.
void setValue(const uint8_t *value, const size_t size, const ChecksumAlgoId type)
Sets the value of the checksum.
Computes a checksum from a byte stream.
static ArrayString getAlternativeNames()
Returns the alternative name(s) of the checksum or the hash algorithm.
virtual ChecksumAlgoId getID() const =0
Returns an unique identifier for the checksum or the hash algorithm.
virtual size_t getSize() const =0
Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) metho...
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static ArrayString getAlternativeNames()
Returns the alternative names of the RIPE-MD160 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA1 hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA224 hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA256 hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA384 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-224 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-256 hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-384 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-512 hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA512 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
Common definitions for libxcks.
constexpr const char * libxcks_domain
Domain for translations (i18n).
Compute Keccak and SHA3 hashes.
Compute sha224 hash and sha256 hash.
Compute sha384 hash and sha512 hash.
bool stringICompare(const std::string &str1, const std::string &str2)
Case-insensitive comparison of two strings.
std::vector< ChecksumAlgoId > ArrayChecksumAlgoId
Array of ids of algorithms of checksums.
ChecksumAlgoId
Ids of algorithms of checksums.
std::vector< std::string > ArrayString
Array of strings.